From: Feross Aboukhadijeh Date: Mon, 9 Mar 2015 21:22:42 +0000 (-0700) Subject: name function expressions for easier debugging X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=5f41ca279a973b0269c2a1fbdd0c4fa1bdf8ba27;p=buffer.git name function expressions for easier debugging --- diff --git a/index.js b/index.js index cd2a1c8..e859ac3 100644 --- a/index.js +++ b/index.js @@ -138,11 +138,11 @@ function SlowBuffer (subject, encoding, noZero) { return buf } -Buffer.isBuffer = function (b) { +Buffer.isBuffer = function isBuffer (b) { return !!(b != null && b._isBuffer) } -Buffer.compare = function (a, b) { +Buffer.compare = function compare (a, b) { if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { throw new TypeError('Arguments must be Buffers') } @@ -161,7 +161,7 @@ Buffer.compare = function (a, b) { return 0 } -Buffer.isEncoding = function (encoding) { +Buffer.isEncoding = function isEncoding (encoding) { switch (String(encoding).toLowerCase()) { case 'hex': case 'utf8': @@ -180,7 +180,7 @@ Buffer.isEncoding = function (encoding) { } } -Buffer.concat = function (list, totalLength) { +Buffer.concat = function concat (list, totalLength) { if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])') if (list.length === 0) { @@ -207,7 +207,7 @@ Buffer.concat = function (list, totalLength) { return buf } -Buffer.byteLength = function (str, encoding) { +Buffer.byteLength = function byteLength (str, encoding) { var ret str = str + '' switch (encoding || 'utf8') { @@ -243,7 +243,7 @@ Buffer.prototype.length = undefined Buffer.prototype.parent = undefined // toString(encoding, start=0, end=buffer.length) -Buffer.prototype.toString = function (encoding, start, end) { +Buffer.prototype.toString = function toString (encoding, start, end) { var loweredCase = false start = start >>> 0 @@ -286,13 +286,13 @@ Buffer.prototype.toString = function (encoding, start, end) { } } -Buffer.prototype.equals = function (b) { +Buffer.prototype.equals = function equals (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true return Buffer.compare(this, b) === 0 } -Buffer.prototype.inspect = function () { +Buffer.prototype.inspect = function inspect () { var str = '' var max = exports.INSPECT_MAX_BYTES if (this.length > 0) { @@ -302,20 +302,20 @@ Buffer.prototype.inspect = function () { return '' } -Buffer.prototype.compare = function (b) { +Buffer.prototype.compare = function compare (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return 0 return Buffer.compare(this, b) } // `get` will be removed in Node 0.13+ -Buffer.prototype.get = function (offset) { +Buffer.prototype.get = function get (offset) { console.log('.get() is deprecated. Access using array indexes instead.') return this.readUInt8(offset) } // `set` will be removed in Node 0.13+ -Buffer.prototype.set = function (v, offset) { +Buffer.prototype.set = function set (v, offset) { console.log('.set() is deprecated. Access using array indexes instead.') return this.writeUInt8(v, offset) } @@ -371,7 +371,7 @@ function utf16leWrite (buf, string, offset, length) { return charsWritten } -Buffer.prototype.write = function (string, offset, length, encoding) { +Buffer.prototype.write = function write (string, offset, length, encoding) { // Support both (string, offset, length, encoding) // and the legacy (string, encoding, offset, length) if (isFinite(offset)) { @@ -433,7 +433,7 @@ Buffer.prototype.write = function (string, offset, length, encoding) { return ret } -Buffer.prototype.toJSON = function () { +Buffer.prototype.toJSON = function toJSON () { return { type: 'Buffer', data: Array.prototype.slice.call(this._arr || this, 0) @@ -507,7 +507,7 @@ function utf16leSlice (buf, start, end) { return res } -Buffer.prototype.slice = function (start, end) { +Buffer.prototype.slice = function slice (start, end) { var len = this.length start = ~~start end = end === undefined ? len : ~~end @@ -552,7 +552,7 @@ function checkOffset (offset, ext, length) { if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') } -Buffer.prototype.readUIntLE = function (offset, byteLength, noAssert) { +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { offset = offset >>> 0 byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) @@ -567,7 +567,7 @@ Buffer.prototype.readUIntLE = function (offset, byteLength, noAssert) { return val } -Buffer.prototype.readUIntBE = function (offset, byteLength, noAssert) { +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { offset = offset >>> 0 byteLength = byteLength >>> 0 if (!noAssert) { @@ -583,22 +583,22 @@ Buffer.prototype.readUIntBE = function (offset, byteLength, noAssert) { return val } -Buffer.prototype.readUInt8 = function (offset, noAssert) { +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length) return this[offset] } -Buffer.prototype.readUInt16LE = function (offset, noAssert) { +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length) return this[offset] | (this[offset + 1] << 8) } -Buffer.prototype.readUInt16BE = function (offset, noAssert) { +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length) return (this[offset] << 8) | this[offset + 1] } -Buffer.prototype.readUInt32LE = function (offset, noAssert) { +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length) return ((this[offset]) | @@ -607,7 +607,7 @@ Buffer.prototype.readUInt32LE = function (offset, noAssert) { (this[offset + 3] * 0x1000000) } -Buffer.prototype.readUInt32BE = function (offset, noAssert) { +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] * 0x1000000) + @@ -616,7 +616,7 @@ Buffer.prototype.readUInt32BE = function (offset, noAssert) { this[offset + 3]) } -Buffer.prototype.readIntLE = function (offset, byteLength, noAssert) { +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { offset = offset >>> 0 byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) @@ -634,7 +634,7 @@ Buffer.prototype.readIntLE = function (offset, byteLength, noAssert) { return val } -Buffer.prototype.readIntBE = function (offset, byteLength, noAssert) { +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { offset = offset >>> 0 byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) @@ -652,25 +652,25 @@ Buffer.prototype.readIntBE = function (offset, byteLength, noAssert) { return val } -Buffer.prototype.readInt8 = function (offset, noAssert) { +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length) if (!(this[offset] & 0x80)) return (this[offset]) return ((0xff - this[offset] + 1) * -1) } -Buffer.prototype.readInt16LE = function (offset, noAssert) { +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset] | (this[offset + 1] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } -Buffer.prototype.readInt16BE = function (offset, noAssert) { +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset + 1] | (this[offset] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } -Buffer.prototype.readInt32LE = function (offset, noAssert) { +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset]) | @@ -679,7 +679,7 @@ Buffer.prototype.readInt32LE = function (offset, noAssert) { (this[offset + 3] << 24) } -Buffer.prototype.readInt32BE = function (offset, noAssert) { +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] << 24) | @@ -688,22 +688,22 @@ Buffer.prototype.readInt32BE = function (offset, noAssert) { (this[offset + 3]) } -Buffer.prototype.readFloatLE = function (offset, noAssert) { +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, true, 23, 4) } -Buffer.prototype.readFloatBE = function (offset, noAssert) { +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, false, 23, 4) } -Buffer.prototype.readDoubleLE = function (offset, noAssert) { +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, true, 52, 8) } -Buffer.prototype.readDoubleBE = function (offset, noAssert) { +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, false, 52, 8) } @@ -714,7 +714,7 @@ function checkInt (buf, value, offset, ext, max, min) { if (offset + ext > buf.length) throw new RangeError('index out of range') } -Buffer.prototype.writeUIntLE = function (value, offset, byteLength, noAssert) { +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value offset = offset >>> 0 byteLength = byteLength >>> 0 @@ -730,7 +730,7 @@ Buffer.prototype.writeUIntLE = function (value, offset, byteLength, noAssert) { return offset + byteLength } -Buffer.prototype.writeUIntBE = function (value, offset, byteLength, noAssert) { +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value offset = offset >>> 0 byteLength = byteLength >>> 0 @@ -746,7 +746,7 @@ Buffer.prototype.writeUIntBE = function (value, offset, byteLength, noAssert) { return offset + byteLength } -Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) @@ -763,7 +763,7 @@ function objectWriteUInt16 (buf, value, offset, littleEndian) { } } -Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) @@ -776,7 +776,7 @@ Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { return offset + 2 } -Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) @@ -796,7 +796,7 @@ function objectWriteUInt32 (buf, value, offset, littleEndian) { } } -Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) @@ -811,7 +811,7 @@ Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { return offset + 4 } -Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) @@ -826,7 +826,7 @@ Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { return offset + 4 } -Buffer.prototype.writeIntLE = function (value, offset, byteLength, noAssert) { +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) { @@ -848,7 +848,7 @@ Buffer.prototype.writeIntLE = function (value, offset, byteLength, noAssert) { return offset + byteLength } -Buffer.prototype.writeIntBE = function (value, offset, byteLength, noAssert) { +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) { @@ -870,7 +870,7 @@ Buffer.prototype.writeIntBE = function (value, offset, byteLength, noAssert) { return offset + byteLength } -Buffer.prototype.writeInt8 = function (value, offset, noAssert) { +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) @@ -880,7 +880,7 @@ Buffer.prototype.writeInt8 = function (value, offset, noAssert) { return offset + 1 } -Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) @@ -893,7 +893,7 @@ Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { return offset + 2 } -Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) @@ -906,7 +906,7 @@ Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { return offset + 2 } -Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) @@ -921,7 +921,7 @@ Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { return offset + 4 } -Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) @@ -951,11 +951,11 @@ function writeFloat (buf, value, offset, littleEndian, noAssert) { return offset + 4 } -Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { return writeFloat(this, value, offset, true, noAssert) } -Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { return writeFloat(this, value, offset, false, noAssert) } @@ -967,16 +967,16 @@ function writeDouble (buf, value, offset, littleEndian, noAssert) { return offset + 8 } -Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { return writeDouble(this, value, offset, true, noAssert) } -Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { return writeDouble(this, value, offset, false, noAssert) } // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function (target, target_start, start, end) { +Buffer.prototype.copy = function copy (target, target_start, start, end) { var self = this // source if (!start) start = 0 @@ -1016,7 +1016,7 @@ Buffer.prototype.copy = function (target, target_start, start, end) { } // fill(value, start=0, end=buffer.length) -Buffer.prototype.fill = function (value, start, end) { +Buffer.prototype.fill = function fill (value, start, end) { if (!value) value = 0 if (!start) start = 0 if (!end) end = this.length @@ -1050,7 +1050,7 @@ Buffer.prototype.fill = function (value, start, end) { * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. * Added in Node 0.12. Only available in browsers that support ArrayBuffer. */ -Buffer.prototype.toArrayBuffer = function () { +Buffer.prototype.toArrayBuffer = function toArrayBuffer () { if (typeof Uint8Array !== 'undefined') { if (Buffer.TYPED_ARRAY_SUPPORT) { return (new Buffer(this)).buffer @@ -1074,7 +1074,7 @@ var BP = Buffer.prototype /** * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods */ -Buffer._augment = function (arr) { +Buffer._augment = function _augment (arr) { arr.constructor = Buffer arr._isBuffer = true