Skip to main content

Crate atomic_replace

Crate atomic_replace 

Source
Expand description

Replace a file atomically.

The new bytes go to a sibling temp file that is renamed over the target, so a reader, a crash or a full disk never sees a half-written file: the target holds either the old bytes or the new ones.

use std::io::Write;

atomic_replace::write("state.json", b"{}\n")?;

atomic_replace::Options::new()
    .create_parent(true)
    .durable(false)
    .write_with("cache/index.bin", |file| file.write_all(b"index"))?;

Structs§

Options
How Options::write and Options::write_with replace a file.

Functions§

sync_dir
Fsync a directory so a rename or create inside it survives a crash.
write
Replace path with bytes using the default Options.