27 releases
Uses old Rust 2015
0.4.0 | Feb 2, 2023 |
---|---|
0.3.1 | Jan 11, 2022 |
0.3.0 | Feb 28, 2021 |
0.2.5 | Oct 9, 2019 |
0.0.9 | Mar 15, 2015 |
#49 in Filesystem
151,354 downloads per month
Used in 44 crates
(20 directly)
14KB
240 lines
rust-atomicwrites
Atomic file-writes. Works on both POSIX and Windows.
The basic idea is to write to temporary files (in the same file
system), and move them when done writing.
This avoids the problem of two programs writing to the same file. For
AllowOverwrite
, rename
is used. For DisallowOverwrite
, link + unlink
is
used instead to raise errors when the target path already exists.
This is mostly a port of the same-named Python package.
Example
use atomicwrites::{AtomicFile,DisallowOverwrite};
let af = AtomicFile::new("foo", DisallowOverwrite);
af.write(|f| {
f.write_all(b"HELLO")
})?;
Alternatives
- tempfile has a
persist
method doing the same thing.
License
Licensed under MIT, see LICENSE
.
Dependencies
~0–7MB
~119K SLoC