accumulate-stream
Transform stream that accumulates and emits data upon events
Last updated 5 years ago by rannn505 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install accumulate-stream 
SYNC missed versions from official npm registry.

accumulate-stream

Transform stream that accumulates and emits data upon events

Installation

$ npm i -S accumulate-stream
$ yarn add accumulate-stream

Usage

import { createReadStream } from 'fs';
import { once } from 'events';
import { AccumulateStream } from 'accumulate-stream';

(async (): void => {
  // file.txt: (2kb)
  // streams are awesome.
  // streams are awesome.
  // ... ...
  const readable = createReadStream('file.txt');
  const accumulator = new AccumulateStream({ size: '1kb', phrase: 'awesome' });
  readable.pipe(accumulateStream);

  // will be emitted every 1kb and 2 writes
  accumulator.on('chunk', ({ buffer }) => console.log(`emitted every chunk write - ${buffer.toString()}`));
  accumulator.on('size', ({ buffer }) => console.log(`emitted every 1kb of chunks - ${buffer.toString()}`));
  accumulator.on('phrase', ({ buffer }) =>
    console.log(`emitted whenever "stream" phrase is detected in chunk - ${buffer.toString()}`),
  );
  accumulator.on('data', ({ buffer }) => console.log(`emitted whenever one of the conditions is met - ${buffer.toString()}`));

  await once(accumulator, 'data');
  console.log(accumulator.getBuffer().toString()); // streams are awesome.
})();

API

// [TBD]

Current Tags

  • 5.0.0                                ...           latest (5 years ago)
  • 5.0.0-next.3                                ...           next (6 years ago)

2 Versions

  • 5.0.0                                ...           5 years ago
  • 5.0.0-next.3                                ...           6 years ago
Maintainers (1)
Downloads
Total 9
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 3
Last Month 4
Dependencies (2)
Dev Dependencies (3)
Dependents (1)

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