Socket
Socket
Sign inDemoInstall

minipass-collect

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

minipass-collect

A Minipass stream that collects all the data into a single chunk

    2.0.1latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
14,072,636
increased by3.54%

Weekly downloads

Package description

What is minipass-collect?

The minipass-collect package is a Node.js stream utility that collects all the data from a stream and then emits a 'collect' event with the collected data. It is built on top of the Minipass stream library, which is a minimal pass-through stream implementation.

What are minipass-collect's main functionalities?

Data collection from streams

This feature allows you to collect all the data from a stream. When the stream ends, the 'collect' event is emitted with the collected data as its argument.

const Collect = require('minipass-collect')
const collectStream = new Collect()
collectStream.on('collect', data => {
  console.log('Collected data:', data)
})
collectStream.write('some data')
collectStream.end()

Other packages similar to minipass-collect

Readme

Source

minipass-collect

A Minipass stream that collects all the data into a single chunk

Note that this buffers ALL data written to it, so it's only good for situations where you are sure the entire stream fits in memory.

Note: this is primarily useful for the Collect.PassThrough class, since Minipass streams already have a .collect() method which returns a promise that resolves to the array of chunks, and a .concat() method that returns the data concatenated into a single Buffer or String.

USAGE

const Collect = require('minipass-collect')

const collector = new Collect()
collector.on('data', allTheData => {
  console.log('all the data!', allTheData)
})

someSourceOfData.pipe(collector)

// note that you can also simply do:
someSourceOfData.pipe(new Minipass()).concat().then(data => ...)
// or even, if someSourceOfData is a Minipass:
someSourceOfData.concat().then(data => ...)
// but you might prefer to have it stream-shaped rather than
// Promise-shaped in some scenarios.

If you want to collect the data, but also act as a passthrough stream, then use Collect.PassThrough instead (for example to memoize streaming responses), and listen on the collect event.

const Collect = require('minipass-collect')

const collector = new Collect.PassThrough()
collector.on('collect', allTheData => {
  console.log('all the data!', allTheData)
})

someSourceOfData.pipe(collector).pipe(someOtherStream)

All minipass options are supported.

FAQs

Last updated on 20 Aug 2023

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the 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