initial commit
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
'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;
|
||||
Reference in New Issue
Block a user