Detalhes do pacote

stream-promise

medikoo3.3mISC3.2.0

Promise that shares Node.js Stream interface

promise, stream, emitter, event-emitter

readme (leia-me)

*nix build status Windows build status Tests coverage Transpilation status npm version

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 streams, promise resolves with concatenated output, in case of writable streams resolve with undefined

To achieve expected result stream should 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); });

Already emitted data is accessible at emittedData property

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); });

Supported options

noCollect boolean (default: false)

Applicable to readable streams. Set to true, if it's not intended to gather stream result and resolve with it.

Then the only purpose of promise would be to indicate a moment when data stream is finalized

Tests

npm test

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.2.0 (2019-03-15)

Features

3.1.0 (2019-01-17)

Bug Fixes

  • writable streams should resolve with udefined (ab21212)

Features

  • expose emitted data at emittedData property (b35d101)

3.0.0 (2019-01-17)

Chores

  • publish as steam-promise (feff7a5)

Features

  • stream to promise approach (8669fab)

BREAKING CHANGES

  • Remove non that useful StreamPromise construtor with utility that converts initialized stream to promise
  • We're skipping v1 to avoid semver confusion with previously published version by other author

1.0.0 (2019-01-14)