a797bd7aee4bef337d8fa06ad0e9d42851a1d071813d5e5e4eb298deab4127546b425d30da68447312919fb0f3cec8a33081887734bb38028098699fdec35b 1.5 KB

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