MCPcopy Create free account
hub / github.com/RetypeOS/parcode / write_all

Method write_all

src/io.rs:70–87  ·  view source on GitHub ↗

Writes a chunk of data atomically to the file sequence. Returns the byte offset where the chunk begins.

(&self, buffer: &[u8])

Source from the content-addressed store, hash-verified

68 ///
69 /// Returns the byte offset where the chunk begins.
70 pub fn write_all(&self, buffer: &[u8]) -> Result<u64> {
71 // Acquire lock.
72 // Since we mostly do memcpy, contention is extremely low.
73 let mut state = self
74 .inner
75 .lock()
76 .map_err(|_| ParcodeError::Internal("Writer mutex poisoned".into()))?;
77
78 let start_offset = state.current_offset;
79
80 // This call usually just copies memory.
81 // It only blocks for disk I/O once every ~16MB of data.
82 state.writer.write_all(buffer)?;
83
84 state.current_offset += buffer.len() as u64;
85
86 Ok(start_offset)
87 }
88
89 /// Forces data to disk.
90 pub fn flush(&self) -> Result<()> {

Callers 6

writeMethod · 0.80
write_syncMethod · 0.80
execute_graph_serialFunction · 0.80
process_nodeFunction · 0.80
mainFunction · 0.80

Calls 1

lenMethod · 0.45

Tested by 1