Socket
Socket
Sign inDemoInstall

stream-promise

Package Overview
Dependencies
11
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stream-promise

Promise that shares Node.js Stream interface


Version published
Weekly downloads
918K
decreased by-2.78%
Maintainers
1
Install size
807 kB
Created
Weekly downloads
 

Changelog

Source

3.2.0 (2019-03-15)

Features

  • noCollect option (8adbdf8)

<a name="3.1.0"></a>

Readme

Source

*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

Keywords

FAQs

Last updated on 15 Mar 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc