1 # fs-write-stream-atomic
3 Like `fs.createWriteStream(...)`, but atomic.
5 Writes to a tmp file and does an atomic `fs.rename` to move it into
8 First rule of debugging: **It's always a race condition.**
13 var fsWriteStreamAtomic = require('fs-write-stream-atomic')
14 // options are optional.
15 var write = fsWriteStreamAtomic('output.txt', options)
16 var read = fs.createReadStream('input.txt')
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.
25 ### `fsWriteStreamAtomic(filename, [options])`
27 * `filename` {String} The file we want to write to
29 * `chown` {Object} User and group to set ownership after write
32 * `encoding` {String} default = 'utf8'
33 * `mode` {Number} default = `0666`
34 * `flags` {String} default = `'w'`