diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-04-20 03:09:25 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-04-24 16:14:29 +0200 |
commit | 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch) | |
tree | 965f6eb89b84d65a62b49008fd972c004832ccd1 /node_modules/bl/bl.js | |
parent | e6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff) |
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules
into one file (plus commons chunks) for every entry point. This results
in a much smaller extension size (almost half). Furthermore we use
yarn/npm even for extension run-time dependencies. This relieves us
from manually vendoring and building dependencies. It's also easier to
understand for new developers familiar with node.
Diffstat (limited to 'node_modules/bl/bl.js')
-rw-r--r-- | node_modules/bl/bl.js | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/node_modules/bl/bl.js b/node_modules/bl/bl.js index f585df172..701c1e564 100644 --- a/node_modules/bl/bl.js +++ b/node_modules/bl/bl.js @@ -38,9 +38,10 @@ util.inherits(BufferList, DuplexStream) BufferList.prototype._offset = function _offset (offset) { var tot = 0, i = 0, _t + if (offset === 0) return [ 0, 0 ] for (; i < this._bufs.length; i++) { _t = tot + this._bufs[i].length - if (offset < _t) + if (offset < _t || i == this._bufs.length - 1) return [ i, offset - tot ] tot = _t } @@ -49,9 +50,10 @@ BufferList.prototype._offset = function _offset (offset) { BufferList.prototype.append = function append (buf) { var i = 0 - , newBuf - if (Array.isArray(buf)) { + if (Buffer.isBuffer(buf)) { + this._appendBuffer(buf); + } else if (Array.isArray(buf)) { for (; i < buf.length; i++) this.append(buf[i]) } else if (buf instanceof BufferList) { @@ -64,17 +66,21 @@ BufferList.prototype.append = function append (buf) { if (typeof buf == 'number') buf = buf.toString() - newBuf = Buffer.isBuffer(buf) ? buf : new Buffer(buf) - this._bufs.push(newBuf) - this.length += newBuf.length + this._appendBuffer(new Buffer(buf)); } return this } +BufferList.prototype._appendBuffer = function appendBuffer (buf) { + this._bufs.push(buf) + this.length += buf.length +} + + BufferList.prototype._write = function _write (buf, encoding, callback) { - this.append(buf) + this._appendBuffer(buf) if (typeof callback == 'function') callback() @@ -107,6 +113,10 @@ BufferList.prototype.get = function get (index) { BufferList.prototype.slice = function slice (start, end) { + if (typeof start == 'number' && start < 0) + start += this.length + if (typeof end == 'number' && end < 0) + end += this.length return this.copy(null, 0, start, end) } @@ -132,8 +142,11 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) { // copy/slice everything if (srcStart === 0 && srcEnd == this.length) { - if (!copy) // slice, just return a full concat - return Buffer.concat(this._bufs) + if (!copy) { // slice, but full concat if multiple buffers + return this._bufs.length === 1 + ? this._bufs[0] + : Buffer.concat(this._bufs, this.length) + } // copy, need to copy individual buffers for (i = 0; i < this._bufs.length; i++) { @@ -174,6 +187,30 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) { return dst } +BufferList.prototype.shallowSlice = function shallowSlice (start, end) { + start = start || 0 + end = end || this.length + + if (start < 0) + start += this.length + if (end < 0) + end += this.length + + var startOffset = this._offset(start) + , endOffset = this._offset(end) + , buffers = this._bufs.slice(startOffset[0], endOffset[0] + 1) + + if (startOffset[1] != 0) + buffers[0] = buffers[0].slice(startOffset[1]) + + if (endOffset[1] == 0) + buffers.pop() + else + buffers[buffers.length-1] = buffers[buffers.length-1].slice(0, endOffset[1]) + + return new BufferList(buffers) +} + BufferList.prototype.toString = function toString (encoding, start, end) { return this.slice(start, end).toString(encoding) } |