WalPack class final
High-performance, crash-safe, single-file binary container combining an immutable chunked snapshot with an append-only CRC32-C Write-Ahead Log (WAL).
Use WalPack.openFile on native platforms, WalPack.inMemory for zero-disk containers (including Web/WASM), or WalPack.open with any custom StorageBackend.
- Available extensions
Properties
- appId → String?
-
Optional 4-character ASCII application identifier (
nullif unset).no setter - backend → StorageBackend
-
Underlying StorageBackend backing this container.
no setter
- baseSeq → int
-
Highest sequence number baked into the current Base Snapshot.
no setter
- chunkCount → int
-
Number of live chunks accessible across Base Snapshot and WAL tail.
no setter
-
chunkKeys
→ Iterable<
String> -
Live (not copied) iterable of all chunk keys in unspecified order.
no setter
-
chunks
→ List<
ChunkMeta> -
Snapshot list of all live ChunkMeta entries.
no setter
- generation → int
-
Current compaction generation (
>= 1).no setter - hashCode → int
-
The hash code for this object.
no setterinherited
-
intIndexNames
→ Iterable<
String> -
Iterable of all registered integer secondary index names.
no setter
- isClosed → bool
-
Whether this container handle has been closed.
no setter
- lastSeq → int
-
Latest committed transaction sequence number.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shouldCompact → bool
-
Returns
trueifoptions.compactionPolicyrecommends compacting now.no setter - stats → WalPackStats
-
Live storage and sequence statistics for this container.
no setter
-
stringIndexNames
→ Iterable<
String> -
Iterable of all registered string secondary index names.
no setter
- walCorruption → String?
-
Description of mid-WAL corruption detected by a read-only open, or
nullif the WAL is intact.no setter
Methods
-
appendOp(
{required int opType, required Uint8List payload, int flags = 0, int codecId = codecIdNone, int? expectedSeq, bool? flush}) → Future< CommitResult> - Convenience helper to append a single WAL operation using the zero-builder fast path.
-
appendOpWith(
{required int opType, required void encode(BinaryWriter writer), int flags = 0, int codecId = codecIdNone, int initialBufferSize = 256, int? expectedSeq, bool? flush}) → Future< CommitResult> -
Convenience helper to append a single WAL operation encoded via
pro_binaryusing the zero-builder fast path. -
backupToFile(
String path) → Future< void> -
Available on WalPack, provided by the WalPackFileBackup extension
Writes a consistent copy of this container topathatomically. -
chunkMeta(
String key) → ChunkMeta? -
Returns the ChunkMeta for
key, ornullif absent. -
close(
) → Future< void> - Flushes pending writes (if any) and closes the underlying backend and lock strategy.
-
commit(
void build(CommitBuilder tx), {int? expectedSeq, bool? flush}) → Future< CommitResult> -
Executes an atomic transaction built by
buildand appends a single CRC32-C-protectedCommitFrameto the WAL tail. -
commitWithRetry<
T> (Future< T> read(), void write(CommitBuilder tx, T value), {int maxAttempts = 5, bool? flush}) → Future<CommitResult> - Runs an optimistic read-modify-write transaction, retrying on CommitConflict.
-
compact(
{void rewrite(CompactBuilder builder)?, int? retainOpsAfterSeq}) → Future< WalPackStats> -
Rebuilds the container using Copy-on-Write (
atomicReplace), reclaiming space from overwritten/deleted chunks and compacted WAL frames while advancing generation. -
containsChunk(
String key) → bool -
Returns
trueif chunkkeycurrently exists in the live index. -
copyTo(
StorageBackend destination) → Future< void> -
Writes a consistent, self-contained copy of the committed container to
destination(replacing its contents) and flushes it. -
deleteChunk(
String key, {int? expectedSeq, bool? flush}) → Future< CommitResult> - Convenience helper to commit a single chunk deletion.
-
exportBytes(
) → Future< Uint8List> -
Returns a consistent copy of the committed container as bytes, ready for
WalPack.inMemory(initialBytes: ...), downloads, or Web persistence (IndexedDB / OPFS). -
keysInRange(
{String? start, String? end, bool includeStart = true, bool includeEnd = false, int? limit}) → List< String> -
Returns live chunk keys in
[start, end)(configurable inclusiveness) in sorted lexicographic order via O(log N + K) binary search. -
keysWithPrefix(
String prefix, {int? limit, String? startAfter}) → List< String> -
Returns live chunk keys matching
prefixin sorted lexicographic order via O(log N + K) binary search. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
putChunk(
String key, Uint8List data, {int? codecId, int kind = chunkKindData, int flags = 0, Map< String, int> ? intIndexes, Map<String, String> ? stringIndexes, int? expectedSeq, bool? flush, bool skipIfUnchanged = false}) → Future<CommitResult> - Convenience helper to commit a single chunk put.
-
putChunkWith(
String key, void encode(BinaryWriter writer), {int? codecId, int kind = chunkKindData, int flags = 0, int initialBufferSize = 1024, Map< String, int> ? intIndexes, Map<String, String> ? stringIndexes, int? expectedSeq, bool? flush, bool skipIfUnchanged = false}) → Future<CommitResult> -
Convenience helper to commit a single chunk encoded with
pro_binary. -
queryIntIndex(
String indexName, {int? min, int? max, bool includeMin = true, bool includeMax = true, int? limit}) → List< String> -
Returns chunk keys whose secondary integer index
indexNamefalls within[min, max]in ascending(value, key)order via O(log N + K) binary search. -
queryStringIndex(
String indexName, {String? prefix, String? min, String? max, bool includeMin = true, bool includeMax = true, int? limit}) → List< String> -
Returns chunk keys whose secondary string index
indexNamematchesprefixor[min, max]in ascending(value, key)order via O(log N + K) binary search. -
readChunk(
String key) → Future< Uint8List?> -
Reads and decompresses chunk
key, returningnullif absent. -
readChunkRaw(
String key) → Future< ({ChunkMeta meta, Uint8List storedBytes})?> -
Reads the raw stored (possibly compressed) bytes of chunk
keyalong with its ChunkMeta without decompressing, ornullif absent. -
readChunks(
Iterable< String> keys) → Future<Map< String, Uint8List> > -
Batch-reads and decodes multiple chunks identified by
keysunder a single shared lock acquisition, sorting reads by file offset and coalescing nearby chunks into contiguous disk reads. -
readChunkWith<
T> (String key, T decode(BinaryReader reader)) → Future< T?> -
Reads chunk
keyand decodes it viadecodeusing apro_binaryBinaryReader, returningnullifkeydoes not exist. -
readIntIndex(
String indexName, {int? min, int? max, bool includeMin = true, bool includeMax = true, int? limit}) → Future< Map< String, Uint8List> > -
Queries secondary integer index
indexNamevia binary search and batch-reads matching chunks in a single coalesced pass. -
readOps(
{int? afterSeq, int? toSeq}) → Future< List< WalOp> > -
Reads and decodes all WAL operations whose sequence numbers fall within
(afterSeq, toSeq]. -
readPrefix(
String prefix, {int? limit, String? startAfter}) → Future< Map< String, Uint8List> > -
Finds keys starting with
prefixvia binary search and batch-reads their decoded payloads in a single coalesced pass. -
readRange(
{String? start, String? end, bool includeStart = true, bool includeEnd = false, int? limit}) → Future< Map< String, Uint8List> > -
Finds keys within
[start, end)via binary search and batch-reads their decoded payloads in a single coalesced pass. -
readStringIndex(
String indexName, {String? prefix, String? min, String? max, bool includeMin = true, bool includeMax = true, int? limit}) → Future< Map< String, Uint8List> > -
Queries secondary string index
indexNamevia binary search and batch-reads matching chunks in a single coalesced pass. -
readWalFrames(
{int? afterSeq, int? toSeq}) → Future< List< WalFrame> > -
Returns WAL frame index metadata filtered by optional
(afterSeq, toSeq]. -
sync(
{bool forceReopen = false}) → Future< SyncResult> - Synchronizes this open handle with external commits or compactions written by other processes or handles.
-
toString(
) → String -
A string representation of this object.
inherited
-
verifyIntegrity(
) → Future< WalPackVerification> - Performs a full structural and CRC32-C integrity verification across the Superblock, Base TOC, every live chunk, and every WAL frame payload.
-
watch(
{Duration interval = const Duration(milliseconds: 250)}) → Stream< SyncResult> - Polls for changes committed by other processes or handles and emits every SyncAppended / SyncCompacted (never SyncUpToDate).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
inMemory(
{WalPackOptions options = const WalPackOptions(), Uint8List? initialBytes}) → Future< WalPack> -
Opens a pure-Dart in-memory container (optionally seeded from existing
serialized
initialBytes), portable across Native VM, WASM, and Web. -
open(
{required StorageBackend backend, WalPackOptions options = const WalPackOptions()}) → Future< WalPack> - Opens a WalPack backed by an arbitrary StorageBackend.
-
openFile(
String path, {WalPackOptions options = const WalPackOptions()}) → Future< WalPack> -
Opens (or creates) a file-backed container at
path.