MemoryStorageBackend class final

Fast, pure-Dart in-memory StorageBackend backed by a growable Uint8List.

Works identically across Native VM, WASM, and Web targets.

With trackDurability: true it also models a volatile OS page cache: only state captured by flush (or an atomicReplace) survives simulateCrash, so tests can detect missing or misordered flushes.

Implemented types

Constructors

MemoryStorageBackend({int initialCapacity = 4096, bool trackDurability = false})
Creates an empty MemoryStorageBackend with initialCapacity.
MemoryStorageBackend.fromBytes(Uint8List bytes, {bool trackDurability = false})
Creates a MemoryStorageBackend initialized with a copy of bytes.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
trackDurability → bool
Whether unflushed writes are discarded by simulateCrash.
final

Methods

atomicReplace(Future<void> buildTemp(StorageBackend temp)) → Future<void>
Atomically swaps the container's contents with a fresh backend built by buildTemp.
override
bytesView() → Uint8List
Returns a zero-copy view of the current valid container bytes.
close() → Future<void>
Releases all resources held by this backend.
override
copyRangeTo({required int sourceOffset, required int length, required StorageBackend dest, required int destOffset}) → Future<void>
Streams length bytes starting at sourceOffset to dest at destOffset.
override
flush() → Future<void>
Flushes buffered OS writes to durable storage.
override
length() → Future<int>
Returns the current byte length of the container (0 if empty/new).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readAt(int offset, int length) → Future<Uint8List>
Reads up to length bytes starting at byte offset.
override
reopen() → Future<void>
Re-opens the underlying storage descriptor after an external compaction replaced the file on disk.
override
simulateCrash() → void
Simulates power loss: discards every write not yet made durable by flush or atomicReplace, and reopens the backend.
toBytes() → Uint8List
Returns an exact-length copy of the current container bytes.
toString() → String
A string representation of this object.
inherited
truncate(int newLength) → Future<void>
Resizes the container to newLength bytes (shrinking discards tail bytes).
override
writeSegmentsAt(int offset, List<Uint8List> segments) → Future<void>
Writes all segments sequentially starting at offset.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited