Nerdy Programmers Mingling
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

stream-to-promise

2.2.0 • Public • Published

stream-to-promise Build Status

Convert streams (readable or writable) to promises

Installing

$ npm install --save[-dev] stream-to-promise

Examples

Readable Streams

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

Writable Streams

streamToPromise(writableStream).then(function () {
  // resolves undefined
})
writableStream.write('data')
writableStream.end() // promise is resolved here

Error Handling

var err = new Error()
streamToPromise(stream).catch(function (error) {
  // error === err
})
stream.emit('error', err) // promise is rejected here

install

npm i stream-to-promise

Downloadsweekly downloads

20,581

version

2.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar