UNPKG

@naturalcycles/nodejs-lib

Version:
25 lines (24 loc) 709 B
"use strict"; 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;