File: README.md

package info (click to toggle)
rust-atomicwrites 0.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 120 kB
  • sloc: makefile: 4
file content (37 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# rust-atomicwrites

[![Build Status](https://travis-ci.org/untitaker/rust-atomicwrites.svg?branch=master)](https://travis-ci.org/untitaker/rust-atomicwrites)
[![Windows build status](https://ci.appveyor.com/api/projects/status/h6642x2d54xl0sev?svg=true)](https://ci.appveyor.com/project/untitaker/rust-atomicwrites)

- [Documentation](https://docs.rs/crate/atomicwrites)
- [Repository](https://github.com/untitaker/rust-atomicwrites)
- [Crates.io](https://crates.io/crates/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](https://github.com/untitaker/python-atomicwrites).

## Example

```rust
use atomicwrites::{AtomicFile,DisallowOverwrite};

let af = AtomicFile::new("foo", DisallowOverwrite);
af.write(|f| {
    f.write_all(b"HELLO")
})?;
```

## Alternatives

- [tempfile](https://github.com/Stebalien/tempfile) has a `persist` method doing the same thing.

## License

Licensed under MIT, see ``LICENSE``.