1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.writableLimit = void 0;
|
4 | const node_stream_1 = require("node:stream");
|
5 | /**
|
6 | * Allows to stop the Readable stream after the pipeline has processed X number of rows.
|
7 | * It counts OUTPUT rows (not input), because this Writable is always at the end of the Pipeline.
|
8 | * It ensures that everything has been processed before issuing a STOP on the readable.
|
9 | */
|
10 | function writableLimit(readable, limit) {
|
11 | let i = 0;
|
12 | return new node_stream_1.Writable({
|
13 | objectMode: true,
|
14 | write(chunk, _, cb) {
|
15 | if (limit === 0)
|
16 | return cb(); // no limit, just passthrough
|
17 | i++;
|
18 | if (i === limit) {
|
19 | console.log(`writableLimit of ${limit} reached`);
|
20 | readable.destroy();
|
21 | cb(); // do we need it?
|
22 | }
|
23 | else {
|
24 | cb(); // passthrough
|
25 | }
|
26 | },
|
27 | });
|
28 | }
|
29 | exports.writableLimit = writableLimit;
|