stream-to-promise

Convert streams (readable or writable) to promises

stream-to-promise

Convert streams (readable or writable) to promises

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 
streamToPromise(writableStream).then(function () {
  // resolves  
});
writableStream.write('data');
writeableStream.end(); // promise is resolved here 
var err = new Error();
streamToPromise(stream).catch(function (error) {
  // error === err; 
});
stream.emit('error', err); // promise is rejected here