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 => {
const readable = createReadStream('file.txt');
const accumulator = new AccumulateStream({ size: '1kb', phrase: 'awesome' });
readable.pipe(accumulateStream);
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());
})();
API
// [TBD]