UNPKG

490 BPlain TextView Raw
1import { Writable } from 'stream'
2import { TransformOptions, WritableTyped } from '../stream.model'
3
4/**
5 * Will push all results to `arr`, will emit nothing in the end.
6 */
7export function writablePushToArray<IN>(arr: IN[], opt: TransformOptions = {}): WritableTyped<IN> {
8 return new Writable({
9 objectMode: true,
10 ...opt,
11 write(chunk: IN, _, cb) {
12 arr.push(chunk)
13 // callback to signal that we processed input, but not emitting any output
14 cb()
15 },
16 })
17}