• Home
Name Date Size #Lines LOC

..--

node_modules/12-May-2024-3,4902,376

test/12-May-2024-400319

.npmignoreD12-May-202437 43

.travis.ymlD12-May-2024141 1211

LICENSED12-May-2024765 1612

README.mdD12-May-20241 KiB3626

index.jsD12-May-20245 KiB177133

package.jsonD12-May-20241.7 KiB6867

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