Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-to-promise-agnostic

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-to-promise-agnostic

Convert streams (readable or writable) to promises using your own standard Promise library.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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
import Promise from 'bluebird; // Or any constructor compatible promise like library of your choice.  
import streamToPromise from 'stream-to-promise-agnostic';

const convert = streamToPromise(Promise,true); // '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)
import {streamToPromise,PromiseFactory,Executor} from 'stream-to-promise-agnostic';
const QPromiseFactory:PromiseFactory = <T>(e:Executor<T>)=>require("q").promise(e);

const convert = streamToPromise(QPromiseFactory);
Step 2: Consume
Readable
convert.toPromise(readableStream).then(array=> {
  // array.length === 3
});
readableStream.emit('data', 1);
readableStream.emit('data', 2);
readableStream.emit('data', 3);
readableStream.emit('end'); // promise is resolved here
Writable
convert.toPromise(writableStream).then(()=> {
  // resolves undefined
});
writableStream.write('data');
writableStream.end(); // promise is resolved here

Keywords

FAQs

Package last updated on 25 Nov 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc