[
][npm-url]
stream-promise
Convert any Stream instance to thenable
So it can be consumed both as a promise and as a stream
Installation
npm install stream-promise
Usage
Stream must be either readable or writable.
In case of readable stream promise resolves with concatenated output, in case of writable streams resolves simply with null
.
To achieve expected result stream should to be converted immediately after initialization.
const streamPromise = require("stream-promise");
streamPromise(someReadableStream);
someReadableStream.then(result => {
console.log("Concatenated stream output", result);
});
streamPromise(someWritabletream);
someReadableStream.then(result => {
console.log("Cumulated stream output", result);
});
Non-destructive way
Sepearate promise (without touching stream object) can be created with to-promise
util:
const streamToPromise = require("stream-promise/to-promise");
const someReadableStreamPromise = streamPromiseTo(someReadableStream);
someReadableStreamPromise.then(result => {
console.log("Concatenated stream output", result);
});
Tests
npm test