@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
25 lines (24 loc) • 709 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformToArray = void 0;
const stream_1 = require("stream");
/**
* Will collect all stream results in the array (keeping it in memory) and emit in the end as one result.
*/
function transformToArray(opt = {}) {
const res = [];
return new stream_1.Transform({
objectMode: true,
...opt,
transform(chunk, _, cb) {
res.push(chunk);
// callback to signal that we processed input, but not emitting any output
cb();
},
final(cb) {
this.push(res);
cb();
},
});
}
exports.transformToArray = transformToArray;