$ gnpm install stream-to-promise
Convert streams (readable or writable) to promises
npm install --save stream-to-promise
streamToPromise(readableStream).then(function (buffer) {
// buffer.length === 3
})
readableStream.emit('data', new Buffer())
readableStream.emit('data', new Buffer())
readableStream.emit('data', new Buffer())
readableStream.emit('end') // promise is resolved here
streamToPromise(writableStream).then(function () {
// resolves undefined
})
writableStream.write('data')
writableStream.end() // promise is resolved here
const err = new Error()
streamToPromise(stream).catch(function (error) {
// error === err
})
stream.emit('error', err) // promise is rejected here
Copyright 2013 - present © cnpmjs.org | Home |