30 releases

Uses old Rust 2015

0.4.3 Dec 28, 2023
0.4.2 Oct 9, 2023
0.4.1 Apr 12, 2023
0.4.0 Feb 2, 2023
0.0.9 Mar 15, 2015

#44 in Filesystem

Download history 62308/week @ 2023-12-02 53123/week @ 2023-12-09 47775/week @ 2023-12-16 26687/week @ 2023-12-23 38427/week @ 2023-12-30 65826/week @ 2024-01-06 80407/week @ 2024-01-13 91661/week @ 2024-01-20 89254/week @ 2024-01-27 99610/week @ 2024-02-03 85871/week @ 2024-02-10 116442/week @ 2024-02-17 127721/week @ 2024-02-24 110945/week @ 2024-03-02 122637/week @ 2024-03-09 91088/week @ 2024-03-16

477,170 downloads per month
Used in 51 crates (23 directly)

MIT license

15KB
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–13MB
~146K SLoC