You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

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