Skip to main content

Module file

Module file 

Source
Expand description

Filesystem-backed kv backend (M4.C — DS-14-storage Audit 4).

FileBackend maps each key to a .bin file under a configured directory. Keys are percent-encoded so any UTF-8 string can be stored safely: [a-zA-Z0-9_-] pass through; everything else is UTF-8 encoded with each byte formatted as lowercase %xx. The encoded filename for any given key is byte-identical to the TS fileBackend impl (packages/pure-ts/src/extra/storage/tiers-node.ts — D159) so a TS-written file can be loaded by a Rust reader on the same directory.

Writes are atomic via tempfile::NamedTempFile::persist: a tempfile is created in the target directory, written in full, then renamed onto the key path. A partially-written file is never visible at the final path, even on process crash. The NamedTempFile Drop impl deletes any tempfile that never made it through persist (covers panics between create and commit).

flush() is a no-op — durability is on per-write basis via the rename. read / delete / list tolerate missing directory + missing key by returning Ok(None) / Ok(()) / Ok(vec![]) respectively (D158).

Cargo feature: gated behind file (default-on).

Structs§

FileBackend
Filesystem-backed StorageBackend.

Functions§

file_append_log
Convenience: append-log tier over a fresh file backend rooted at dir.
file_append_log_default
Convenience: append-log tier over a fresh file backend with AppendLogStorageOptions::default + a JsonCodec.
file_backend
Convenience constructor returning an Arc<FileBackend>. Use this when sharing a single backend across multiple tiers (the paired { snapshot, wal } pattern from DS-14-storage §a). For non-default configuration use Arc::new(FileBackend::new(dir).with_include_hidden(true)).
file_kv
Convenience: kv tier over a fresh file backend rooted at dir.
file_kv_default
Convenience: kv tier over a fresh file backend with KvStorageOptions::default + a JsonCodec.
file_snapshot
Convenience: snapshot tier over a fresh file backend rooted at dir. Mirror of crate::memory_snapshot for filesystem persistence.
file_snapshot_default
Convenience: snapshot tier over a fresh file backend with SnapshotStorageOptions::default + a JsonCodec.