34 lines
819 B
JavaScript
34 lines
819 B
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
var _stream = require('stream');
|
|
|
|
// Discards "bytesToDiscard" bytes
|
|
class DiscardStream extends _stream.Transform {
|
|
constructor() {
|
|
let bytesToDiscard = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
|
|
|
|
super();
|
|
this.bytesToDiscard = bytesToDiscard;
|
|
this.byteCount = 0;
|
|
this.done = false;
|
|
}
|
|
_transform(chunk, encoding, cb) {
|
|
if (this.done) return cb(null, chunk);
|
|
|
|
this.byteCount += chunk.length;
|
|
|
|
if (this.byteCount > this.bytesToDiscard) {
|
|
this.done = true;
|
|
const bytesToKeep = this.byteCount - this.bytesToDiscard;
|
|
const firstChunk = chunk.slice(-bytesToKeep);
|
|
return cb(null, firstChunk);
|
|
}
|
|
cb(null);
|
|
}
|
|
}
|
|
|
|
exports.default = DiscardStream; |