1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.transformBuffer = void 0;
|
4 | const stream_1 = require("stream");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function transformBuffer(opt) {
|
11 | const { batchSize } = opt;
|
12 | let buf = [];
|
13 | return new stream_1.Transform({
|
14 | objectMode: true,
|
15 | ...opt,
|
16 | transform(chunk, _encoding, cb) {
|
17 | buf.push(chunk);
|
18 | if (buf.length >= batchSize) {
|
19 | cb(null, buf);
|
20 | buf = [];
|
21 | }
|
22 | else {
|
23 | cb();
|
24 | }
|
25 | },
|
26 | final(cb) {
|
27 | if (buf.length) {
|
28 | this.push(buf);
|
29 | buf = [];
|
30 | }
|
31 | cb();
|
32 | },
|
33 | });
|
34 | }
|
35 | exports.transformBuffer = transformBuffer;
|