Sha256: 28cf97c59d2d1642ace39370ff3c6d7b3b90e7798b316d7e50f2f9f3ca2044cc

Contents?: true

Size: 1.01 KB

Versions: 102

Compression:

Stored size: 1.01 KB

Contents

# fs-write-stream-atomic

Like `fs.createWriteStream(...)`, but atomic.

Writes to a tmp file and does an atomic `fs.rename` to move it into
place when it's done.

First rule of debugging: **It's always a race condition.**

## USAGE

```javascript
var fsWriteStreamAtomic = require('fs-write-stream-atomic')
// options are optional.
var write = fsWriteStreamAtomic('output.txt', options)
var read = fs.createReadStream('input.txt')
read.pipe(write)

// When the write stream emits a 'finish' or 'close' event,
// you can be sure that it is moved into place, and contains
// all the bytes that were written to it, even if something else
// was writing to `output.txt` at the same time.
```

### `fsWriteStreamAtomic(filename, [options])`

* `filename` {String} The file we want to write to
* `options` {Object}
  * `chown` {Object} User and group to set ownership after write
    * `uid` {Number}
    * `gid` {Number}
  * `encoding` {String} default = 'utf8'
  * `mode` {Number} default = `0666`
  * `flags` {String} default = `'w'`

Version data entries

102 entries across 100 versions & 14 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.18.0 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.18.2 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.16.1 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.15.2 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.18.4 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.18.1 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.14.0 test/dummy/node_modules/fs-write-stream-atomic/README.md
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/fs-write-stream-atomic/README.md
tang-0.2.1 spec/tang_app/node_modules/fs-write-stream-atomic/README.md
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/fs-write-stream-atomic/README.md
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/fs-write-stream-atomic/README.md
ruby2js-4.0.4 lib/tasks/testrails/node_modules/fs-write-stream-atomic/README.md
ruby2js-4.0.3 lib/tasks/testrails/node_modules/fs-write-stream-atomic/README.md
tang-0.2.0 spec/tang_app/node_modules/fs-write-stream-atomic/README.md
tang-0.1.0 spec/tang_app/node_modules/fs-write-stream-atomic/README.md
tang-0.0.9 spec/tang_app/node_modules/fs-write-stream-atomic/README.md
enju_library-0.3.8 spec/dummy/node_modules/fs-write-stream-atomic/README.md
ilog-0.4.1 node_modules/fs-write-stream-atomic/README.md