1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.transformToArray = void 0;
|
4 | const node_stream_1 = require("node:stream");
|
5 | /**
|
6 | * Will collect all stream results in the array (keeping it in memory) and emit in the end as one result.
|
7 | */
|
8 | function transformToArray(opt = {}) {
|
9 | const res = [];
|
10 | return new node_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 | }
|
24 | exports.transformToArray = transformToArray;
|