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