Skip to main content

atomic_write_with

Function atomic_write_with 

Source
pub fn atomic_write_with<F>(path: &Path, write_fn: F) -> Result<()>
where F: FnOnce(&mut BufWriter<File>) -> Result<()>,
Expand description

Atomically write the destination at path by streaming through a BufWriter. The closure runs against a buffered writer over a sibling temp file. On success, the buffer is flushed, the file is fsync’d, and the temp file is renamed over path.

Use this for line-by-line or chunked writes (e.g. JSONL compaction). For a one-shot byte write, prefer atomic_write.