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

stream-consumers

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-consumers

a user-land copy of the node:stream/consumers library from Node.js

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Stream Consumers

node:stream/consumers for Deno, Browsers and older nodejs versions

(targeting NodeJS v16.7.0+ only? use node:stream/consumers instead)

Install

This package is ESM only: Node 12.20+ is needed to use it and it must be imported instead of required.
npm install stream-consumers

Use

The utility consumer functions provide common options for consuming streams.

They are accessed using:

import { arrayBuffer, blob, json, text } from 'stream-consumers'
streamConsumers.arrayBuffer(stream)
  • stream {ReadableStream|stream.Readable|AsyncIterator}
  • Returns: {Promise} Fulfills with an ArrayBuffer containing the full contents of the stream.
streamConsumers.blob(stream)
  • stream {ReadableStream|stream.Readable|AsyncIterator}
  • Returns: {Promise} Fulfills with a {Blob} containing the full contents of the stream.
streamConsumers.json(stream)
  • stream {ReadableStream|stream.Readable|AsyncIterator}
  • Returns: {Promise} Fulfills with the contents of the stream parsed as a UTF-8 encoded string that is then passed through JSON.parse().
streamConsumers.text(stream)
  • stream {ReadableStream|stream.Readable|AsyncIterator}
  • Returns: {Promise} Fulfills with the contents of the stream parsed as a UTF-8 encoded string.
streamConsumers.buffer(stream) ⚠️ Not supported

Use arrayBuffer(stream).then(Buffer.from) instead if you realy want a Buffer.
(you should be using uint8array instead for better Browser/Deno bundles.

Alternative native methods

Response can be a grate hack to abuse it's feature to convert mostly anything else without the need for this library. new Response(new ReadableStream({...})).json()

But this can't work with async iterator or node:streams that's when you should be using this utility stream consumers that all accepts async iterators.

Keywords

FAQs

Package last updated on 17 Jan 2022

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