@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
16 lines (15 loc) • 419 B
JavaScript
import { Writable } from 'node:stream';
/**
* Will push all results to `arr`, will emit nothing in the end.
*/
export function writablePushToArray(arr, opt = {}) {
return new Writable({
objectMode: true,
...opt,
write(chunk, _, cb) {
arr.push(chunk);
// callback to signal that we processed input, but not emitting any output
cb();
},
});
}