stream-collect

Collects the output of a stream

ISC 16 个版本
安装
npm install stream-collect
yarn add stream-collect
pnpm add stream-collect
bun add stream-collect
README

Stream collect

npm version

Collects a readable streams data as a string, buffer or, for object streams, an array.

npm install stream-collect

collect.Collect(options)

Create a pass through stream with a collect() method and collect event.

const { Collect } = require('stream-collect');
const file = fs.createReadableStream('myfile');

// Collect using a promise
file.pipe(new Collect())
  .collect()
  .then(buffer => { /* use contents */ });

// Collect using an event
file.pipe(new Collect())
  .on('collect', buffer => { /* use contents */ });

// Collect as a string rather than a buffer
file.pipe(new Collect({ encoding: 'utf-8' }))
  .collect()
  .then(string => { /* use contents */ });

// Collect an object stream
file
  .pipe(new Transform({
    readableObjectMode: true,
    transform(chunk, encoding, callback) {
      chunk.toString().split('').forEach(char = this.push(char));
      callback();
    }
  })
  .pipe(new Collect())
  .on('collect', array => { /* -> array of characters */ });  

collect(stream, [encoding], [cb])

Collect a streams contents returning a promise or callback.

const collect = require('stream-collect');
const file = fs.createReadableStream('myfile');

// Collect using a promise
collect(file)
  .then(fileContents => { /* use contents */ });

// Collect using a callback
collect(file, (error, fileContents) => { /* use contents */ });

// Specify an encoding
collect(file, 'base64')
  .then(fileContents => { /* use contents */ });

collect.CollectObjects()

A Collect stream with objectMode set to true.

collect.addToStream(stream)

Augment any stream with a collect event.

Returns the augmented stream.

版本列表
2.2.0 2021-04-12
2.1.5 2019-07-11
2.1.4 2019-06-17
2.1.3 2018-11-10
2.1.2 2018-10-09
2.1.1 2018-04-29
2.1.0 2017-11-05
2.0.0 2017-11-05
1.3.1 2016-08-01
1.3.0 2015-06-28
1.2.1 2015-06-28
1.2.0 2015-06-28
1.1.0 2015-06-27
1.0.2 2015-06-24
1.0.1 2015-02-01
1.0.0 2015-02-01