Need help with stream-to-promise?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

bendrucker
133 Stars 15 Forks MIT License 73 Commits 0 Opened issues

Description

Convert streams (readable or writable) to promises

Services available

!
?

Need anything else?

Contributors list

# 19,725
Terrafo...
Angular
firebas...
angular...
56 commits
# 195
nextjs
graphql...
travis
postman
2 commits
# 175,277
wikiped...
Markdow...
google-...
Flask
1 commit
# 175,865
PHP
CSS
brew
debian
1 commit
# 64,834
HTML
React
Electro...
TypeScr...
1 commit
# 20,979
CSS
Zsh
node-js
test-fr...
1 commit

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.