Created
June 7, 2016 11:34
-
-
Save bergos/ab7d85b66c343dbe30089052cbad7cda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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