node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
'use strict';
module.exports = SliceStream;
var Transform = require('readable-stream/transform');
var inherits = require("util").inherits;
inherits(SliceStream, Transform);
function SliceStream(opts, sliceFn) {
if (!(this instanceof SliceStream)) {
return new SliceStream(opts, sliceFn);
}
this._opts = opts;
this._accumulatedLength = 0;
this.sliceFn = sliceFn;
Transform.call(this);
}
SliceStream.prototype._transform = function (chunk, encoding, callback) {
this._accumulatedLength += chunk.length;
if (this._accumulatedLength >= this._opts.length) {
//todo handle more than one slice in a stream
var offset = chunk.length - (this._accumulatedLength - this._opts.length);
this.sliceFn(chunk.slice(0, offset), true, chunk.slice(offset));
callback();
} else {
this.sliceFn(chunk);
callback();
}
};