Files
2026-09-01 18:33:56 +00:00

40 lines
833 B
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stream = require('stream');
class SizeStream extends _stream.Transform {
constructor(cb) {
super({ objectMode: true });
this.streamSize = 0;
this.cb = cb;
}
_transform(chunk, encoding, cb) {
if (this.cb) return this._transformCb(chunk, encoding, cb);
// Update hash sum objects
this.streamSize = this.streamSize + chunk.length;
cb();
}
_flush(cb) {
if (this.cb) return this._flushCb(cb);
const size = this.streamSize;
this.push({ size });
cb(null);
}
_transformCb(chunk, encoding, cb) {
this.streamSize = this.streamSize + chunk.length;
cb(null, chunk);
}
_flushCb(cb) {
const size = this.streamSize;
this.cb(size);
cb(null);
}
}
exports.default = SizeStream;