node-tailor
Version:
Tailor assembles a web page from multiple fragments
22 lines (17 loc) • 458 B
JavaScript
;
const stream = require('stream');
module.exports = class ContentLengthStream extends stream.Transform {
constructor(callback) {
super();
this.callback = callback;
this.contentSize = 0;
}
_transform(chunk, encoding, done) {
this.contentSize += chunk.length;
done(null, chunk);
}
_flush(done) {
this.callback(this.contentSize);
done();
}
};