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

stream-to-promise

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-to-promise

Convert streams (readable or writable) to promises

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
523K
decreased by-33.17%
Maintainers
1
Weekly downloads
 
Created

What is stream-to-promise?

The 'stream-to-promise' npm package is a utility that converts a stream into a promise. This is particularly useful when working with Node.js streams and you need to handle the completion of a stream operation using async/await or promise-based syntax.

What are stream-to-promise's main functionalities?

Convert Stream to Promise

This feature allows you to convert a readable stream into a promise. The promise resolves when the stream ends, making it easier to handle stream completion in an async/await context.

const streamToPromise = require('stream-to-promise');
const fs = require('fs');

async function readFile() {
  const readStream = fs.createReadStream('example.txt');
  await streamToPromise(readStream);
  console.log('Stream has ended');
}

readFile();

Handle Stream Errors

This feature demonstrates how to handle errors that occur during the stream operation. The promise will reject if the stream emits an 'error' event, allowing you to catch and handle the error using try/catch.

const streamToPromise = require('stream-to-promise');
const fs = require('fs');

async function readFile() {
  const readStream = fs.createReadStream('nonexistent.txt');
  try {
    await streamToPromise(readStream);
  } catch (error) {
    console.error('Stream error:', error);
  }
}

readFile();

Other packages similar to stream-to-promise

Keywords

FAQs

Package last updated on 25 May 2020

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