Skip to content

Instantly share code, notes, and snippets.

@bergos
Created June 7, 2016 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bergos/ab7d85b66c343dbe30089052cbad7cda to your computer and use it in GitHub Desktop.
Save bergos/ab7d85b66c343dbe30089052cbad7cda to your computer and use it in GitHub Desktop.
'use strict'
const Readable = require('stream').Readable
class StreamWrapper extends Readable {
constructor (stream) {
super()
this._read = () => {
stream.read().then((chunk) => {
if (chunk.done) {
this.push(null)
} else {
this.push(new Buffer(chunk.value))
}
}).catch((err) => {
this.emit('error', err)
})
}
}
}
module.exports = StreamWrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment