31 releases

Uses old Rust 2015

0.4.4 Sep 19, 2024
0.4.3 Dec 28, 2023
0.4.2 Oct 9, 2023
0.4.1 Apr 12, 2023
0.0.9 Mar 15, 2015

#44 in Filesystem

Download history 101053/week @ 2024-07-28 95844/week @ 2024-08-04 102223/week @ 2024-08-11 104871/week @ 2024-08-18 111692/week @ 2024-08-25 97326/week @ 2024-09-01 101174/week @ 2024-09-08 87024/week @ 2024-09-15 88953/week @ 2024-09-22 92109/week @ 2024-09-29 87505/week @ 2024-10-06 82554/week @ 2024-10-13 75317/week @ 2024-10-20 76521/week @ 2024-10-27 76164/week @ 2024-11-03 77880/week @ 2024-11-10

310,000 downloads per month
Used in 59 crates (24 directly)

MIT license

16KB
240 lines

rust-atomicwrites

Build Status Windows build status

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

~2–11MB
~137K SLoC