minipass-collect
A Minipass stream that collects all the data into a single chunk
Last updated a year ago by isaacs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install minipass-collect 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 2.0.1                                ...           latest (a year ago)

5 Versions

  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 4
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE