README.md
1# fs-write-stream-atomic
2
3Like `fs.createWriteStream(...)`, but atomic.
4
5Writes to a tmp file and does an atomic `fs.rename` to move it into
6place when it's done.
7
8First rule of debugging: **It's always a race condition.**
9
10## USAGE
11
12```javascript
13var fsWriteStreamAtomic = require('fs-write-stream-atomic')
14// options are optional.
15var write = fsWriteStreamAtomic('output.txt', options)
16var read = fs.createReadStream('input.txt')
17read.pipe(write)
18
19// When the write stream emits a 'finish' or 'close' event,
20// you can be sure that it is moved into place, and contains
21// all the bytes that were written to it, even if something else
22// was writing to `output.txt` at the same time.
23```
24
25### `fsWriteStreamAtomic(filename, [options])`
26
27* `filename` {String} The file we want to write to
28* `options` {Object}
29 * `chown` {Object} User and group to set ownership after write
30 * `uid` {Number}
31 * `gid` {Number}
32 * `encoding` {String} default = 'utf8'
33 * `mode` {Number} default = `0666`
34 * `flags` {String} default = `'w'`
35
36