* prototype.
*/
function Buffer (subject, encoding, noZero) {
- if (!(this instanceof Buffer))
- return new Buffer(subject, encoding, noZero)
+ if (!(this instanceof Buffer)) return new Buffer(subject, encoding, noZero)
var type = typeof subject
-
- // Find the length
var length
+
if (type === 'number') {
length = +subject
} else if (type === 'string') {
length = Buffer.byteLength(subject, encoding)
- } else if (type === 'object' && subject !== null) { // assume object is array-like
- if (subject.type === 'Buffer' && isArray(subject.data))
- subject = subject.data
+ } else if (type === 'object' && subject !== null) {
+ // assume object is array-like
+ if (subject.type === 'Buffer' && isArray(subject.data)) subject = subject.data
length = +subject.length
} else {
throw new TypeError('must start with number, buffer, array or string')
}
- if (length > kMaxLength)
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
- 'size: 0x' + kMaxLength.toString(16) + ' bytes')
+ if (length > kMaxLength) {
+ throw new RangeError('Attempt to allocate Buffer larger than maximum size: 0x' +
+ kMaxLength.toString(16) + ' bytes')
+ }
- if (length < 0)
- length = 0
- else
- length >>>= 0 // Coerce to uint32.
+ if (length < 0) length = 0
+ else length >>>= 0 // coerce to uint32
var self = this
if (Buffer.TYPED_ARRAY_SUPPORT) {
} else if (isArrayish(subject)) {
// Treat array-ish objects as a byte array
if (Buffer.isBuffer(subject)) {
- for (i = 0; i < length; i++)
+ for (i = 0; i < length; i++) {
self[i] = subject.readUInt8(i)
+ }
} else {
- for (i = 0; i < length; i++)
+ for (i = 0; i < length; i++) {
self[i] = ((subject[i] % 256) + 256) % 256
+ }
}
} else if (type === 'string') {
self.write(subject, 0, encoding)
}
}
- if (length > 0 && length <= Buffer.poolSize)
- self.parent = rootParent
+ if (length > 0 && length <= Buffer.poolSize) self.parent = rootParent
return self
}
function SlowBuffer (subject, encoding, noZero) {
- if (!(this instanceof SlowBuffer))
- return new SlowBuffer(subject, encoding, noZero)
+ if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding, noZero)
var buf = new Buffer(subject, encoding, noZero)
delete buf.parent
}
Buffer.compare = function (a, b) {
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b))
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
throw new TypeError('Arguments must be Buffers')
+ }
if (a === b) return 0
return utf16leSlice(this, start, end)
default:
- if (loweredCase)
- throw new TypeError('Unknown encoding: ' + encoding)
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase()
loweredCase = true
}
var max = exports.INSPECT_MAX_BYTES
if (this.length > 0) {
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
- if (this.length > max)
- str += ' ... '
+ if (this.length > max) str += ' ... '
}
return '<Buffer ' + str + '>'
}
offset = Number(offset) || 0
- if (length < 0 || offset < 0 || offset > this.length)
+ if (length < 0 || offset < 0 || offset > this.length) {
throw new RangeError('attempt to write outside buffer bounds')
+ }
var remaining = this.length - offset
if (!length) {
if (start < 0) {
start += len
- if (start < 0)
- start = 0
+ if (start < 0) start = 0
} else if (start > len) {
start = len
}
if (end < 0) {
end += len
- if (end < 0)
- end = 0
+ if (end < 0) end = 0
} else if (end > len) {
end = len
}
- if (end < start)
- end = start
+ if (end < start) end = start
var newBuf
if (Buffer.TYPED_ARRAY_SUPPORT) {
}
}
- if (newBuf.length)
- newBuf.parent = this.parent || this
+ if (newBuf.length) newBuf.parent = this.parent || this
return newBuf
}
* Need to make sure that buffer isn't trying to write out of bounds.
*/
function checkOffset (offset, ext, length) {
- if ((offset % 1) !== 0 || offset < 0)
- throw new RangeError('offset is not uint')
- if (offset + ext > length)
- throw new RangeError('Trying to access beyond buffer length')
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
}
Buffer.prototype.readUIntLE = function (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
- if (!noAssert)
- checkOffset(offset, byteLength, this.length)
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
var val = this[offset]
var mul = 1
var i = 0
- while (++i < byteLength && (mul *= 0x100))
+ while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul
+ }
return val
}
Buffer.prototype.readUIntBE = function (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
- if (!noAssert)
+ if (!noAssert) {
checkOffset(offset, byteLength, this.length)
+ }
var val = this[offset + --byteLength]
var mul = 1
- while (byteLength > 0 && (mul *= 0x100))
+ while (byteLength > 0 && (mul *= 0x100)) {
val += this[offset + --byteLength] * mul
+ }
return val
}
Buffer.prototype.readUInt8 = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 1, this.length)
+ if (!noAssert) checkOffset(offset, 1, this.length)
return this[offset]
}
Buffer.prototype.readUInt16LE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 2, this.length)
+ if (!noAssert) checkOffset(offset, 2, this.length)
return this[offset] | (this[offset + 1] << 8)
}
Buffer.prototype.readUInt16BE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 2, this.length)
+ if (!noAssert) checkOffset(offset, 2, this.length)
return (this[offset] << 8) | this[offset + 1]
}
Buffer.prototype.readUInt32LE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 4, this.length)
+ if (!noAssert) checkOffset(offset, 4, this.length)
return ((this[offset]) |
(this[offset + 1] << 8) |
}
Buffer.prototype.readUInt32BE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 4, this.length)
+ if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset] * 0x1000000) +
- ((this[offset + 1] << 16) |
- (this[offset + 2] << 8) |
- this[offset + 3])
+ ((this[offset + 1] << 16) |
+ (this[offset + 2] << 8) |
+ this[offset + 3])
}
Buffer.prototype.readIntLE = function (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
- if (!noAssert)
- checkOffset(offset, byteLength, this.length)
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
var val = this[offset]
var mul = 1
var i = 0
- while (++i < byteLength && (mul *= 0x100))
+ while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul
+ }
mul *= 0x80
- if (val >= mul)
- val -= Math.pow(2, 8 * byteLength)
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
return val
}
Buffer.prototype.readIntBE = function (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
- if (!noAssert)
- checkOffset(offset, byteLength, this.length)
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
var i = byteLength
var mul = 1
var val = this[offset + --i]
- while (i > 0 && (mul *= 0x100))
+ while (i > 0 && (mul *= 0x100)) {
val += this[offset + --i] * mul
+ }
mul *= 0x80
- if (val >= mul)
- val -= Math.pow(2, 8 * byteLength)
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
return val
}
Buffer.prototype.readInt8 = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 1, this.length)
- if (!(this[offset] & 0x80))
- return (this[offset])
+ 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) {
- if (!noAssert)
- checkOffset(offset, 2, this.length)
+ 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) {
- if (!noAssert)
- checkOffset(offset, 2, this.length)
+ 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) {
- if (!noAssert)
- checkOffset(offset, 4, this.length)
+ if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset]) |
- (this[offset + 1] << 8) |
- (this[offset + 2] << 16) |
- (this[offset + 3] << 24)
+ (this[offset + 1] << 8) |
+ (this[offset + 2] << 16) |
+ (this[offset + 3] << 24)
}
Buffer.prototype.readInt32BE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 4, this.length)
+ if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset] << 24) |
- (this[offset + 1] << 16) |
- (this[offset + 2] << 8) |
- (this[offset + 3])
+ (this[offset + 1] << 16) |
+ (this[offset + 2] << 8) |
+ (this[offset + 3])
}
Buffer.prototype.readFloatLE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 4, this.length)
+ if (!noAssert) checkOffset(offset, 4, this.length)
return ieee754.read(this, offset, true, 23, 4)
}
Buffer.prototype.readFloatBE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 4, this.length)
+ if (!noAssert) checkOffset(offset, 4, this.length)
return ieee754.read(this, offset, false, 23, 4)
}
Buffer.prototype.readDoubleLE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 8, this.length)
+ if (!noAssert) checkOffset(offset, 8, this.length)
return ieee754.read(this, offset, true, 52, 8)
}
Buffer.prototype.readDoubleBE = function (offset, noAssert) {
- if (!noAssert)
- checkOffset(offset, 8, this.length)
+ if (!noAssert) checkOffset(offset, 8, this.length)
return ieee754.read(this, offset, false, 52, 8)
}
value = +value
offset = offset >>> 0
byteLength = byteLength >>> 0
- if (!noAssert)
- checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
+ if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
var mul = 1
var i = 0
this[offset] = value & 0xFF
- while (++i < byteLength && (mul *= 0x100))
+ while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = (value / mul) >>> 0 & 0xFF
+ }
return offset + byteLength
}
value = +value
offset = offset >>> 0
byteLength = byteLength >>> 0
- if (!noAssert)
- checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
+ if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
var i = byteLength - 1
var mul = 1
this[offset + i] = value & 0xFF
- while (--i >= 0 && (mul *= 0x100))
+ while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = (value / mul) >>> 0 & 0xFF
+ }
return offset + byteLength
}
Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 1, 0xff, 0)
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
this[offset] = value
return offset + 1
Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 2, 0xffff, 0)
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = value
this[offset + 1] = (value >>> 8)
- } else objectWriteUInt16(this, value, offset, true)
+ } else {
+ objectWriteUInt16(this, value, offset, true)
+ }
return offset + 2
}
Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 2, 0xffff, 0)
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8)
this[offset + 1] = value
- } else objectWriteUInt16(this, value, offset, false)
+ } else {
+ objectWriteUInt16(this, value, offset, false)
+ }
return offset + 2
}
Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 4, 0xffffffff, 0)
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset + 3] = (value >>> 24)
this[offset + 2] = (value >>> 16)
this[offset + 1] = (value >>> 8)
this[offset] = value
- } else objectWriteUInt32(this, value, offset, true)
+ } else {
+ objectWriteUInt32(this, value, offset, true)
+ }
return offset + 4
}
Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 4, 0xffffffff, 0)
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24)
this[offset + 1] = (value >>> 16)
this[offset + 2] = (value >>> 8)
this[offset + 3] = value
- } else objectWriteUInt32(this, value, offset, false)
+ } else {
+ objectWriteUInt32(this, value, offset, false)
+ }
return offset + 4
}
value = +value
offset = offset >>> 0
if (!noAssert) {
- checkInt(this,
- value,
- offset,
- byteLength,
- Math.pow(2, 8 * byteLength - 1) - 1,
- -Math.pow(2, 8 * byteLength - 1))
+ checkInt(
+ this, value, offset, byteLength,
+ Math.pow(2, 8 * byteLength - 1) - 1,
+ -Math.pow(2, 8 * byteLength - 1)
+ )
}
var i = 0
var mul = 1
var sub = value < 0 ? 1 : 0
this[offset] = value & 0xFF
- while (++i < byteLength && (mul *= 0x100))
+ while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
+ }
return offset + byteLength
}
value = +value
offset = offset >>> 0
if (!noAssert) {
- checkInt(this,
- value,
- offset,
- byteLength,
- Math.pow(2, 8 * byteLength - 1) - 1,
- -Math.pow(2, 8 * byteLength - 1))
+ checkInt(
+ this, value, offset, byteLength,
+ Math.pow(2, 8 * byteLength - 1) - 1,
+ -Math.pow(2, 8 * byteLength - 1)
+ )
}
var i = byteLength - 1
var mul = 1
var sub = value < 0 ? 1 : 0
this[offset + i] = value & 0xFF
- while (--i >= 0 && (mul *= 0x100))
+ while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
+ }
return offset + byteLength
}
Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 1, 0x7f, -0x80)
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
if (value < 0) value = 0xff + value + 1
this[offset] = value
Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 2, 0x7fff, -0x8000)
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = value
this[offset + 1] = (value >>> 8)
- } else objectWriteUInt16(this, value, offset, true)
+ } else {
+ objectWriteUInt16(this, value, offset, true)
+ }
return offset + 2
}
Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 2, 0x7fff, -0x8000)
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8)
this[offset + 1] = value
- } else objectWriteUInt16(this, value, offset, false)
+ } else {
+ objectWriteUInt16(this, value, offset, false)
+ }
return offset + 2
}
Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = value
this[offset + 1] = (value >>> 8)
this[offset + 2] = (value >>> 16)
this[offset + 3] = (value >>> 24)
- } else objectWriteUInt32(this, value, offset, true)
+ } else {
+ objectWriteUInt32(this, value, offset, true)
+ }
return offset + 4
}
Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
value = +value
offset = offset >>> 0
- if (!noAssert)
- checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
if (value < 0) value = 0xffffffff + value + 1
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24)
this[offset + 1] = (value >>> 16)
this[offset + 2] = (value >>> 8)
this[offset + 3] = value
- } else objectWriteUInt32(this, value, offset, false)
+ } else {
+ objectWriteUInt32(this, value, offset, false)
+ }
return offset + 4
}
}
function writeFloat (buf, value, offset, littleEndian, noAssert) {
- if (!noAssert)
+ if (!noAssert) {
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
+ }
ieee754.write(buf, value, offset, littleEndian, 23, 4)
return offset + 4
}
}
function writeDouble (buf, value, offset, littleEndian, noAssert) {
- if (!noAssert)
+ if (!noAssert) {
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
+ }
ieee754.write(buf, value, offset, littleEndian, 52, 8)
return offset + 8
}
if (target.length === 0 || self.length === 0) return 0
// Fatal error conditions
- if (target_start < 0)
+ if (target_start < 0) {
throw new RangeError('targetStart out of bounds')
+ }
if (start < 0 || start >= self.length) throw new RangeError('sourceStart out of bounds')
if (end < 0) throw new RangeError('sourceEnd out of bounds')
// Are we oob?
- if (end > this.length)
- end = this.length
- if (target.length - target_start < end - start)
+ if (end > this.length) end = this.length
+ if (target.length - target_start < end - start) {
end = target.length - target_start + start
+ }
var len = end - start
function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; i++) {
- if ((i + offset >= dst.length) || (i >= src.length))
- break
+ if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i]
}
return i