UNPKG

709 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.transformToArray = void 0;
4const stream_1 = require("stream");
5/**
6 * Will collect all stream results in the array (keeping it in memory) and emit in the end as one result.
7 */
8function transformToArray(opt = {}) {
9 const res = [];
10 return new stream_1.Transform({
11 objectMode: true,
12 ...opt,
13 transform(chunk, _, cb) {
14 res.push(chunk);
15 // callback to signal that we processed input, but not emitting any output
16 cb();
17 },
18 final(cb) {
19 this.push(res);
20 cb();
21 },
22 });
23}
24exports.transformToArray = transformToArray;