stream-to-promise
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/stream-to-promise package

3.0.0 • Public • Published

stream-to-promise Build Status

Convert streams (readable or writable) to promises

Installing

npm install --save 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

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

Readme

Keywords

Package Sidebar

Install

npm i stream-to-promise

Weekly Downloads

651,123

Version

3.0.0

License

MIT

Unpacked Size

4.03 kB

Total Files

4

Last publish

Collaborators

  • bendrucker