MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / open

Method open

nodedb-wal/src/reader.rs:46–70  ·  view source on GitHub ↗

Open a WAL file for reading. If the file begins with a valid `WALP` preamble (16 bytes), it is consumed and stored for use as AAD during decryption. Files without a preamble (unencrypted segments) start reading from offset 0 directly. Automatically opens the companion double-write buffer file (`*.dwb`) if it exists alongside the WAL file.

(path: &Path)

Source from the content-addressed store, hash-verified

44 /// Automatically opens the companion double-write buffer file
45 /// (`*.dwb`) if it exists alongside the WAL file.
46 pub fn open(path: &Path) -> Result<Self> {
47 let mut file = File::open(path)?;
48 let dwb_path = path.with_extension("dwb");
49 let double_write = if dwb_path.exists() {
50 crate::double_write::DoubleWriteBuffer::open(
51 &dwb_path,
52 crate::double_write::DwbMode::Buffered,
53 )
54 .ok()
55 } else {
56 None
57 };
58
59 // Attempt to read the preamble at offset 0.
60 // If the first 4 bytes match WAL_PREAMBLE_MAGIC, consume the full
61 // 16-byte preamble and validate it. Otherwise rewind to 0.
62 let (segment_preamble, start_offset) = try_read_preamble(&mut file)?;
63
64 Ok(Self {
65 file,
66 offset: start_offset,
67 segment_preamble,
68 double_write,
69 })
70 }
71
72 /// The preamble read from this segment file, if present.
73 ///

Calls 4

try_read_preambleFunction · 0.85
openFunction · 0.50
existsMethod · 0.45
okMethod · 0.45

Tested by 1