blob: 2a0b4222ef277683d6aa6164580b7121a3406b0c [file] [log] [blame]
import { default as Stream } from "stream"
var Transform = Stream.Transform;
/*
* A through transform stream that counts number of bytes being piped to it
* @param {function} onUpdate Callback function that gets called with number of
* bytes read when a chunk is read
* @class
*/
export class StreamByteCounter extends Transform {
constructor(onUpdate) {
super();
this._onUpdate = onUpdate;
}
_transform(chunk, encoding, cb) {
this._onUpdate(chunk.length);
this.push(chunk)
cb();
}
}