1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.transformLimit = void 0;
|
4 | const stream_1 = require("stream");
|
5 |
|
6 |
|
7 |
|
8 | function transformLimit(limit, opt = {}) {
|
9 | let index = 0;
|
10 | let ended = false;
|
11 | return new stream_1.Transform({
|
12 | objectMode: true,
|
13 | ...opt,
|
14 | transform(chunk, _encoding, cb) {
|
15 | index++;
|
16 | if (!ended) {
|
17 | cb(null, chunk);
|
18 | }
|
19 | else {
|
20 | cb(null);
|
21 | }
|
22 | if (limit && index === limit) {
|
23 | ended = true;
|
24 | console.log(`transformLimit: limit of ${limit} reached`);
|
25 |
|
26 | }
|
27 | },
|
28 | });
|
29 | }
|
30 | exports.transformLimit = transformLimit;
|