source: trip-planner-front/node_modules/minipass-collect/README.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1# minipass-collect
2
3A Minipass stream that collects all the data into a single chunk
4
5Note that this buffers ALL data written to it, so it's only good for
6situations where you are sure the entire stream fits in memory.
7
8Note: this is primarily useful for the `Collect.PassThrough` class, since
9Minipass streams already have a `.collect()` method which returns a promise
10that resolves to the array of chunks, and a `.concat()` method that returns
11the data concatenated into a single Buffer or String.
12
13## USAGE
14
15```js
16const Collect = require('minipass-collect')
17
18const collector = new Collect()
19collector.on('data', allTheData => {
20 console.log('all the data!', allTheData)
21})
22
23someSourceOfData.pipe(collector)
24
25// note that you can also simply do:
26someSourceOfData.pipe(new Minipass()).concat().then(data => ...)
27// or even, if someSourceOfData is a Minipass:
28someSourceOfData.concat().then(data => ...)
29// but you might prefer to have it stream-shaped rather than
30// Promise-shaped in some scenarios.
31```
32
33If you want to collect the data, but _also_ act as a passthrough stream,
34then use `Collect.PassThrough` instead (for example to memoize streaming
35responses), and listen on the `collect` event.
36
37```js
38const Collect = require('minipass-collect')
39
40const collector = new Collect.PassThrough()
41collector.on('collect', allTheData => {
42 console.log('all the data!', allTheData)
43})
44
45someSourceOfData.pipe(collector).pipe(someOtherStream)
46```
47
48All [minipass options](http://npm.im/minipass) are supported.
Note: See TracBrowser for help on using the repository browser.