1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.SizeStack = void 0;
|
4 | const js_lib_1 = require("@naturalcycles/js-lib");
|
5 | const colors_1 = require("../colors");
|
6 | const zip_util_1 = require("../util/zip.util");
|
7 | class SizeStack extends js_lib_1.NumberStack {
|
8 | constructor(name, size) {
|
9 | super(size);
|
10 | this.name = name;
|
11 | this.total = 0;
|
12 | }
|
13 | push(item) {
|
14 | this.total += item;
|
15 | return super.push(item);
|
16 | }
|
17 | getStats() {
|
18 |
|
19 | return [
|
20 | ' ' + this.name,
|
21 | 'avg',
|
22 | (0, colors_1.yellow)((0, js_lib_1._hb)(this.avg())),
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | 'total',
|
28 | (0, colors_1.yellow)((0, js_lib_1._hb)(this.total)),
|
29 | ].join(' ');
|
30 | }
|
31 | static async countItem(item, logger, sizes, sizesZipped) {
|
32 | if (!sizes)
|
33 | return;
|
34 |
|
35 | try {
|
36 | const buf = Buffer.from(JSON.stringify(item));
|
37 | sizes.push(buf.byteLength);
|
38 | if (sizesZipped) {
|
39 | const { byteLength } = await (0, zip_util_1.gzipBuffer)(buf);
|
40 | sizesZipped.push(byteLength);
|
41 | }
|
42 | }
|
43 | catch (err) {
|
44 | logger.warn(`transformLogProgress failed to JSON.stringify the chunk: ${err.message}`);
|
45 | }
|
46 | }
|
47 | }
|
48 | exports.SizeStack = SizeStack;
|