writify
v1.0.0
Published
Write stream wrapper that supports async initialization and flush function
Downloads
45
Readme
writify
Write stream wrapper that supports async initialization and flush function.
npm install writifyvar ws = writify(init, [flush], [opts])
var ws = writify.obj(init, [flush], [opts])
Wraps a new writable stream (or object stream) by passing init callback function.
Supports optional flush function that is called before 'finish' emitted.
var writify = require('writify')
...
var ws = writify((cb) => {
// async initialization, error handling
mkdirp('/tmp/foo/', (err) => {
if (err) return cb(err)
cb(null, fs.createWriteStream('/tmp/foo/bar.txt'))
})
}, (cb) => {
// flush before finish
fs.rename('/tmp/foo/bar.txt', './dest.txt', cb)
})
fs.createReadStream('loremipsum.txt').pipe(ws)
License
MIT
