put method

  1. @override
Uint8List? put(
  1. Uint8List key,
  2. Uint8List value
)
override

Add a key, value pair to the underlying store, overwriting any existing values. Returns the old value if one existed, otherwise returns the new value.

put(utf8.encode('foo'), utf8.encode('bar')); // returns 'bar' (new)
put(utf8.encode('foo'), utf8.encode('baz')); // returns 'bar' (old)
get(utf8.encode('foo')); // returns 'baz'

Implementation

@override
Uint8List? put(Uint8List key, Uint8List value) {
  _guard();
  final result = _recordPool.put(key, value, true) as RecordBlock;
  if (result.isNew) {
    // New insert — result is the new record
    _header.numBytes += result.size;
    _header.numRecords += 1;
    if (_flush && !batch) flush();
    return result.value;
  } else {
    // Overwrite — result is the old record
    final previous = result.value;
    final current = _recordPool.get(key) as RecordBlock;
    _header.numBytes += current.size - result.size;
    if (_flush && !batch) flush();
    return previous;
  }
}