UNPKG

@naturalcycles/nodejs-lib

Version:
25 lines 782 B
"use strict"; 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