@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
25 lines • 782 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
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, _encoding, cb) {
res.push(chunk);
// callback to signal that we processed input, but not emitting any output
cb();
},
final(cb) {
// tslint:disable-next-line:no-invalid-this
this.push(res);
cb();
},
});
}
exports.transformToArray = transformToArray;
//# sourceMappingURL=transformToArray.js.map