Files
strom/src/functions/collect.ts
Jerry Kurian a11aa10d16 Clean up
2019-09-26 09:23:09 -04:00

19 lines
503 B
TypeScript

import { Transform, TransformOptions } from "stream";
export function collect(options: TransformOptions = {}): Transform {
const collected: any[] = [];
return new Transform({
...options,
transform(data, encoding, callback) {
collected.push(data);
callback();
},
flush(callback) {
this.push(
options.objectMode ? collected : Buffer.concat(collected),
);
callback();
},
});
}