stream-to-promise-agnostic
(Built using TypeScript. Type declarations are embedded.)
Convert streams (readable or writable) to promises using your own standard Promise library.
Usage
Step 1: Import
Using an ES6 style compatible Promise library
; ; // 'true' indicates a Promise constructor
streamToPromise
can take any PromiseConstructorLike
(see lib.d.ts) constructor when the second param equals true
Using a Promise library that doesn't have a constructor (Example: Q)
;; ;
Step 2: Consume
Readable
convert.toPromisereadableStream.then;readableStream.emit'data', 1;readableStream.emit'data', 2;readableStream.emit'data', 3;readableStream.emit'end'; // promise is resolved here
Writable
convert.toPromisewritableStream.then;writableStream.write'data';writableStream.end; // promise is resolved here