Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

buffer

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer - npm Package Compare versions

Comparing version 5.7.0 to 6.0.0

1

AUTHORS.md

@@ -66,2 +66,3 @@ # Authors

- Fedor Nezhivoi (gyzerok@users.noreply.github.com)
- shuse2 (shus.toda@gmail.com)
- Peter Newman (peternewman@users.noreply.github.com)

@@ -68,0 +69,0 @@ - mathmakgakpak (44949126+mathmakgakpak@users.noreply.github.com)

556

index.js

@@ -11,5 +11,5 @@ /*!

var base64 = require('base64-js')
var ieee754 = require('ieee754')
var customInspectSymbol =
const base64 = require('base64-js')
const ieee754 = require('ieee754')
const customInspectSymbol =
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation

@@ -23,3 +23,3 @@ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation

var K_MAX_LENGTH = 0x7fffffff
const K_MAX_LENGTH = 0x7fffffff
exports.kMaxLength = K_MAX_LENGTH

@@ -54,4 +54,4 @@

try {
var arr = new Uint8Array(1)
var proto = { foo: function () { return 42 } }
const arr = new Uint8Array(1)
const proto = { foo: function () { return 42 } }
Object.setPrototypeOf(proto, Uint8Array.prototype)

@@ -86,3 +86,3 @@ Object.setPrototypeOf(arr, proto)

// Return an augmented `Uint8Array` instance
var buf = new Uint8Array(length)
const buf = new Uint8Array(length)
Object.setPrototypeOf(buf, Buffer.prototype)

@@ -150,3 +150,3 @@ return buf

var valueOf = value.valueOf && value.valueOf()
const valueOf = value.valueOf && value.valueOf()
if (valueOf != null && valueOf !== value) {

@@ -156,3 +156,3 @@ return Buffer.from(valueOf, encodingOrOffset, length)

var b = fromObject(value)
const b = fromObject(value)
if (b) return b

@@ -162,5 +162,3 @@

typeof value[Symbol.toPrimitive] === 'function') {
return Buffer.from(
value[Symbol.toPrimitive]('string'), encodingOrOffset, length
)
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
}

@@ -250,6 +248,6 @@

var length = byteLength(string, encoding) | 0
var buf = createBuffer(length)
const length = byteLength(string, encoding) | 0
let buf = createBuffer(length)
var actual = buf.write(string, encoding)
const actual = buf.write(string, encoding)

@@ -267,5 +265,5 @@ if (actual !== length) {

function fromArrayLike (array) {
var length = array.length < 0 ? 0 : checked(array.length) | 0
var buf = createBuffer(length)
for (var i = 0; i < length; i += 1) {
const length = array.length < 0 ? 0 : checked(array.length) | 0
const buf = createBuffer(length)
for (let i = 0; i < length; i += 1) {
buf[i] = array[i] & 255

@@ -278,3 +276,3 @@ }

if (isInstance(arrayView, Uint8Array)) {
var copy = new Uint8Array(arrayView)
const copy = new Uint8Array(arrayView)
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)

@@ -294,3 +292,3 @@ }

var buf
let buf
if (byteOffset === undefined && length === undefined) {

@@ -312,4 +310,4 @@ buf = new Uint8Array(array)

if (Buffer.isBuffer(obj)) {
var len = checked(obj.length) | 0
var buf = createBuffer(len)
const len = checked(obj.length) | 0
const buf = createBuffer(len)

@@ -369,6 +367,6 @@ if (buf.length === 0) {

var x = a.length
var y = b.length
let x = a.length
let y = b.length
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
if (a[i] !== b[i]) {

@@ -414,3 +412,3 @@ x = a[i]

var i
let i
if (length === undefined) {

@@ -423,6 +421,6 @@ length = 0

var buffer = Buffer.allocUnsafe(length)
var pos = 0
const buffer = Buffer.allocUnsafe(length)
let pos = 0
for (i = 0; i < list.length; ++i) {
var buf = list[i]
const buf = list[i]
if (isInstance(buf, Uint8Array)) {

@@ -458,8 +456,8 @@ Uint8Array.prototype.set.call(

var len = string.length
var mustMatch = (arguments.length > 2 && arguments[2] === true)
const len = string.length
const mustMatch = (arguments.length > 2 && arguments[2] === true)
if (!mustMatch && len === 0) return 0
// Use a for loop to avoid recursion
var loweredCase = false
let loweredCase = false
for (;;) {

@@ -495,3 +493,3 @@ switch (encoding) {

function slowToString (encoding, start, end) {
var loweredCase = false
let loweredCase = false

@@ -574,3 +572,3 @@ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only

function swap (b, n, m) {
var i = b[n]
const i = b[n]
b[n] = b[m]

@@ -581,7 +579,7 @@ b[m] = i

Buffer.prototype.swap16 = function swap16 () {
var len = this.length
const len = this.length
if (len % 2 !== 0) {
throw new RangeError('Buffer size must be a multiple of 16-bits')
}
for (var i = 0; i < len; i += 2) {
for (let i = 0; i < len; i += 2) {
swap(this, i, i + 1)

@@ -593,7 +591,7 @@ }

Buffer.prototype.swap32 = function swap32 () {
var len = this.length
const len = this.length
if (len % 4 !== 0) {
throw new RangeError('Buffer size must be a multiple of 32-bits')
}
for (var i = 0; i < len; i += 4) {
for (let i = 0; i < len; i += 4) {
swap(this, i, i + 3)

@@ -606,7 +604,7 @@ swap(this, i + 1, i + 2)

Buffer.prototype.swap64 = function swap64 () {
var len = this.length
const len = this.length
if (len % 8 !== 0) {
throw new RangeError('Buffer size must be a multiple of 64-bits')
}
for (var i = 0; i < len; i += 8) {
for (let i = 0; i < len; i += 8) {
swap(this, i, i + 7)

@@ -621,3 +619,3 @@ swap(this, i + 1, i + 6)

Buffer.prototype.toString = function toString () {
var length = this.length
const length = this.length
if (length === 0) return ''

@@ -637,4 +635,4 @@ if (arguments.length === 0) return utf8Slice(this, 0, length)

Buffer.prototype.inspect = function inspect () {
var str = ''
var max = exports.INSPECT_MAX_BYTES
let str = ''
const max = exports.INSPECT_MAX_BYTES
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()

@@ -693,10 +691,10 @@ if (this.length > max) str += ' ... '

var x = thisEnd - thisStart
var y = end - start
var len = Math.min(x, y)
let x = thisEnd - thisStart
let y = end - start
const len = Math.min(x, y)
var thisCopy = this.slice(thisStart, thisEnd)
var targetCopy = target.slice(start, end)
const thisCopy = this.slice(thisStart, thisEnd)
const targetCopy = target.slice(start, end)
for (var i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
if (thisCopy[i] !== targetCopy[i]) {

@@ -780,5 +778,5 @@ x = thisCopy[i]

function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
var indexSize = 1
var arrLength = arr.length
var valLength = val.length
let indexSize = 1
let arrLength = arr.length
let valLength = val.length

@@ -807,5 +805,5 @@ if (encoding !== undefined) {

var i
let i
if (dir) {
var foundIndex = -1
let foundIndex = -1
for (i = byteOffset; i < arrLength; i++) {

@@ -823,4 +821,4 @@ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {

for (i = byteOffset; i >= 0; i--) {
var found = true
for (var j = 0; j < valLength; j++) {
let found = true
for (let j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {

@@ -852,3 +850,3 @@ found = false

offset = Number(offset) || 0
var remaining = buf.length - offset
const remaining = buf.length - offset
if (!length) {

@@ -863,3 +861,3 @@ length = remaining

var strLen = string.length
const strLen = string.length

@@ -869,4 +867,5 @@ if (length > strLen / 2) {

}
for (var i = 0; i < length; ++i) {
var parsed = parseInt(string.substr(i * 2, 2), 16)
let i
for (i = 0; i < length; ++i) {
const parsed = parseInt(string.substr(i * 2, 2), 16)
if (numberIsNaN(parsed)) return i

@@ -921,3 +920,3 @@ buf[offset + i] = parsed

var remaining = this.length - offset
const remaining = this.length - offset
if (length === undefined || length > remaining) length = remaining

@@ -931,3 +930,3 @@

var loweredCase = false
let loweredCase = false
for (;;) {

@@ -982,9 +981,9 @@ switch (encoding) {

end = Math.min(buf.length, end)
var res = []
const res = []
var i = start
let i = start
while (i < end) {
var firstByte = buf[i]
var codePoint = null
var bytesPerSequence = (firstByte > 0xEF)
const firstByte = buf[i]
let codePoint = null
let bytesPerSequence = (firstByte > 0xEF)
? 4

@@ -998,3 +997,3 @@ : (firstByte > 0xDF)

if (i + bytesPerSequence <= end) {
var secondByte, thirdByte, fourthByte, tempCodePoint
let secondByte, thirdByte, fourthByte, tempCodePoint

@@ -1061,6 +1060,6 @@ switch (bytesPerSequence) {

// We go 1 magnitude less, for safety
var MAX_ARGUMENTS_LENGTH = 0x1000
const MAX_ARGUMENTS_LENGTH = 0x1000
function decodeCodePointsArray (codePoints) {
var len = codePoints.length
const len = codePoints.length
if (len <= MAX_ARGUMENTS_LENGTH) {

@@ -1071,4 +1070,4 @@ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()

// Decode in chunks to avoid "call stack size exceeded".
var res = ''
var i = 0
let res = ''
let i = 0
while (i < len) {

@@ -1084,6 +1083,6 @@ res += String.fromCharCode.apply(

function asciiSlice (buf, start, end) {
var ret = ''
let ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; ++i) {
for (let i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i] & 0x7F)

@@ -1095,6 +1094,6 @@ }

function latin1Slice (buf, start, end) {
var ret = ''
let ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; ++i) {
for (let i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i])

@@ -1106,3 +1105,3 @@ }

function hexSlice (buf, start, end) {
var len = buf.length
const len = buf.length

@@ -1112,4 +1111,4 @@ if (!start || start < 0) start = 0

var out = ''
for (var i = start; i < end; ++i) {
let out = ''
for (let i = start; i < end; ++i) {
out += hexSliceLookupTable[buf[i]]

@@ -1121,6 +1120,6 @@ }

function utf16leSlice (buf, start, end) {
var bytes = buf.slice(start, end)
var res = ''
const bytes = buf.slice(start, end)
let res = ''
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
for (var i = 0; i < bytes.length - 1; i += 2) {
for (let i = 0; i < bytes.length - 1; i += 2) {
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))

@@ -1132,3 +1131,3 @@ }

Buffer.prototype.slice = function slice (start, end) {
var len = this.length
const len = this.length
start = ~~start

@@ -1153,3 +1152,3 @@ end = end === undefined ? len : ~~end

var newBuf = this.subarray(start, end)
const newBuf = this.subarray(start, end)
// Return an augmented `Uint8Array` instance

@@ -1175,5 +1174,5 @@ Object.setPrototypeOf(newBuf, Buffer.prototype)

var val = this[offset]
var mul = 1
var i = 0
let val = this[offset]
let mul = 1
let i = 0
while (++i < byteLength && (mul *= 0x100)) {

@@ -1194,4 +1193,4 @@ val += this[offset + i] * mul

var val = this[offset + --byteLength]
var mul = 1
let val = this[offset + --byteLength]
let mul = 1
while (byteLength > 0 && (mul *= 0x100)) {

@@ -1247,2 +1246,46 @@ val += this[offset + --byteLength] * mul

Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
offset = offset >>> 0
validateNumber(offset, 'offset')
const first = this[offset]
const last = this[offset + 7]
if (first === undefined || last === undefined) {
boundsError(offset, this.length - 8)
}
const lo = first +
this[++offset] * 2 ** 8 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 24
const hi = this[++offset] +
this[++offset] * 2 ** 8 +
this[++offset] * 2 ** 16 +
last * 2 ** 24
return BigInt(lo) + (BigInt(hi) << BigInt(32))
})
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
offset = offset >>> 0
validateNumber(offset, 'offset')
const first = this[offset]
const last = this[offset + 7]
if (first === undefined || last === undefined) {
boundsError(offset, this.length - 8)
}
const hi = first * 2 ** 24 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 8 +
this[++offset]
const lo = this[++offset] * 2 ** 24 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 8 +
last
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
})
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {

@@ -1253,5 +1296,5 @@ offset = offset >>> 0

var val = this[offset]
var mul = 1
var i = 0
let val = this[offset]
let mul = 1
let i = 0
while (++i < byteLength && (mul *= 0x100)) {

@@ -1272,5 +1315,5 @@ val += this[offset + i] * mul

var i = byteLength
var mul = 1
var val = this[offset + --i]
let i = byteLength
let mul = 1
let val = this[offset + --i]
while (i > 0 && (mul *= 0x100)) {

@@ -1296,3 +1339,3 @@ val += this[offset + --i] * mul

if (!noAssert) checkOffset(offset, 2, this.length)
var val = this[offset] | (this[offset + 1] << 8)
const val = this[offset] | (this[offset + 1] << 8)
return (val & 0x8000) ? val | 0xFFFF0000 : val

@@ -1304,3 +1347,3 @@ }

if (!noAssert) checkOffset(offset, 2, this.length)
var val = this[offset + 1] | (this[offset] << 8)
const val = this[offset + 1] | (this[offset] << 8)
return (val & 0x8000) ? val | 0xFFFF0000 : val

@@ -1329,2 +1372,44 @@ }

Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
offset = offset >>> 0
validateNumber(offset, 'offset')
const first = this[offset]
const last = this[offset + 7]
if (first === undefined || last === undefined) {
boundsError(offset, this.length - 8)
}
const val = this[offset + 4] +
this[offset + 5] * 2 ** 8 +
this[offset + 6] * 2 ** 16 +
(last << 24) // Overflow
return (BigInt(val) << BigInt(32)) +
BigInt(first +
this[++offset] * 2 ** 8 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 24)
})
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
offset = offset >>> 0
validateNumber(offset, 'offset')
const first = this[offset]
const last = this[offset + 7]
if (first === undefined || last === undefined) {
boundsError(offset, this.length - 8)
}
const val = (first << 24) + // Overflow
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 8 +
this[++offset]
return (BigInt(val) << BigInt(32)) +
BigInt(this[++offset] * 2 ** 24 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 8 +
last)
})
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {

@@ -1366,8 +1451,8 @@ offset = offset >>> 0

if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1
const maxBytes = Math.pow(2, 8 * byteLength) - 1
checkInt(this, value, offset, byteLength, maxBytes, 0)
}
var mul = 1
var i = 0
let mul = 1
let i = 0
this[offset] = value & 0xFF

@@ -1387,8 +1472,8 @@ while (++i < byteLength && (mul *= 0x100)) {

if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1
const maxBytes = Math.pow(2, 8 * byteLength) - 1
checkInt(this, value, offset, byteLength, maxBytes, 0)
}
var i = byteLength - 1
var mul = 1
let i = byteLength - 1
let mul = 1
this[offset + i] = value & 0xFF

@@ -1455,2 +1540,54 @@ while (--i >= 0 && (mul *= 0x100)) {

function wrtBigUInt64LE (buf, value, offset, min, max) {
checkIntBI(value, min, max, buf, offset, 7)
let lo = Number(value & BigInt(0xffffffff))
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
return offset
}
function wrtBigUInt64BE (buf, value, offset, min, max) {
checkIntBI(value, min, max, buf, offset, 7)
let lo = Number(value & BigInt(0xffffffff))
buf[offset + 7] = lo
lo = lo >> 8
buf[offset + 6] = lo
lo = lo >> 8
buf[offset + 5] = lo
lo = lo >> 8
buf[offset + 4] = lo
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
buf[offset + 3] = hi
hi = hi >> 8
buf[offset + 2] = hi
hi = hi >> 8
buf[offset + 1] = hi
hi = hi >> 8
buf[offset] = hi
return offset + 8
}
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
})
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
})
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {

@@ -1460,3 +1597,3 @@ value = +value

if (!noAssert) {
var limit = Math.pow(2, (8 * byteLength) - 1)
const limit = Math.pow(2, (8 * byteLength) - 1)

@@ -1466,5 +1603,5 @@ checkInt(this, value, offset, byteLength, limit - 1, -limit)

var i = 0
var mul = 1
var sub = 0
let i = 0
let mul = 1
let sub = 0
this[offset] = value & 0xFF

@@ -1485,3 +1622,3 @@ while (++i < byteLength && (mul *= 0x100)) {

if (!noAssert) {
var limit = Math.pow(2, (8 * byteLength) - 1)
const limit = Math.pow(2, (8 * byteLength) - 1)

@@ -1491,5 +1628,5 @@ checkInt(this, value, offset, byteLength, limit - 1, -limit)

var i = byteLength - 1
var mul = 1
var sub = 0
let i = byteLength - 1
let mul = 1
let sub = 0
this[offset + i] = value & 0xFF

@@ -1556,2 +1693,10 @@ while (--i >= 0 && (mul *= 0x100)) {

Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
})
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
})
function checkIEEE754 (buf, value, offset, ext, max, min) {

@@ -1624,3 +1769,3 @@ if (offset + ext > buf.length) throw new RangeError('Index out of range')

var len = end - start
const len = end - start

@@ -1663,3 +1808,3 @@ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {

if (val.length === 1) {
var code = val.charCodeAt(0)
const code = val.charCodeAt(0)
if ((encoding === 'utf8' && code < 128) ||

@@ -1691,3 +1836,3 @@ encoding === 'latin1') {

var i
let i
if (typeof val === 'number') {

@@ -1698,6 +1843,6 @@ for (i = start; i < end; ++i) {

} else {
var bytes = Buffer.isBuffer(val)
const bytes = Buffer.isBuffer(val)
? val
: Buffer.from(val, encoding)
var len = bytes.length
const len = bytes.length
if (len === 0) {

@@ -1715,6 +1860,139 @@ throw new TypeError('The value "' + val +

// CUSTOM ERRORS
// =============
// Simplified versions from Node, changed for Buffer-only usage
var errors = {}
function E (sym, getMessage, Base) {
errors[sym] = class NodeError extends Base {
constructor () {
super()
Object.defineProperty(this, 'message', {
value: getMessage.apply(this, arguments),
writable: true,
configurable: true
})
// Add the error code to the name to include it in the stack trace.
this.name = `${this.name} [${sym}]`
// Access the stack to generate the error message including the error code
// from the name.
this.stack // eslint-disable-line no-unused-expressions
// Reset the name to the actual name.
delete this.name
}
get code () {
return sym
}
set code (value) {
Object.defineProperty(this, 'code', {
configurable: true,
enumerable: true,
value,
writable: true
})
}
toString () {
return `${this.name} [${sym}]: ${this.message}`
}
}
}
E('ERR_BUFFER_OUT_OF_BOUNDS',
function (name) {
if (name) {
return `${name} is outside of buffer bounds`
}
return 'Attempt to access memory outside buffer bounds'
}, RangeError)
E('ERR_INVALID_ARG_TYPE',
function (name, actual) {
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
}, TypeError)
E('ERR_OUT_OF_RANGE',
function (str, range, input) {
let msg = `The value of "${str}" is out of range.`
let received = input
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
received = addNumericalSeparator(String(input))
} else if (typeof input === 'bigint') {
received = String(input)
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
received = addNumericalSeparator(received)
}
received += 'n'
}
msg += ` It must be ${range}. Received ${received}`
return msg
}, RangeError)
function addNumericalSeparator (val) {
let res = ''
let i = val.length
const start = val[0] === '-' ? 1 : 0
for (; i >= start + 4; i -= 3) {
res = `_${val.slice(i - 3, i)}${res}`
}
return `${val.slice(0, i)}${res}`
}
// CHECK FUNCTIONS
// ===============
function checkBounds (buf, offset, byteLength) {
validateNumber(offset, 'offset')
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
boundsError(offset, buf.length - (byteLength + 1))
}
}
function checkIntBI (value, min, max, buf, offset, byteLength) {
if (value > max || value < min) {
const n = typeof min === 'bigint' ? 'n' : ''
let range
if (byteLength > 3) {
if (min === 0 || min === BigInt(0)) {
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`
} else {
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
`${(byteLength + 1) * 8 - 1}${n}`
}
} else {
range = `>= ${min}${n} and <= ${max}${n}`
}
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
}
checkBounds(buf, offset, byteLength)
}
function validateNumber (value, name) {
if (typeof value !== 'number') {
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
}
}
function boundsError (value, length, type) {
if (Math.floor(value) !== value) {
validateNumber(value, type)
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
}
if (length < 0) {
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
}
throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
`>= ${type ? 1 : 0} and <= ${length}`,
value)
}
// HELPER FUNCTIONS
// ================
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g

@@ -1737,8 +2015,8 @@ function base64clean (str) {

units = units || Infinity
var codePoint
var length = string.length
var leadSurrogate = null
var bytes = []
let codePoint
const length = string.length
let leadSurrogate = null
const bytes = []
for (var i = 0; i < length; ++i) {
for (let i = 0; i < length; ++i) {
codePoint = string.charCodeAt(i)

@@ -1817,4 +2095,4 @@

function asciiToBytes (str) {
var byteArray = []
for (var i = 0; i < str.length; ++i) {
const byteArray = []
for (let i = 0; i < str.length; ++i) {
// Node's code seems to be doing this and not & 0x7F..

@@ -1827,5 +2105,5 @@ byteArray.push(str.charCodeAt(i) & 0xFF)

function utf16leToBytes (str, units) {
var c, hi, lo
var byteArray = []
for (var i = 0; i < str.length; ++i) {
let c, hi, lo
const byteArray = []
for (let i = 0; i < str.length; ++i) {
if ((units -= 2) < 0) break

@@ -1848,3 +2126,4 @@

function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; ++i) {
let i
for (i = 0; i < length; ++i) {
if ((i + offset >= dst.length) || (i >= src.length)) break

@@ -1871,8 +2150,8 @@ dst[i + offset] = src[i]

// See: https://github.com/feross/buffer/issues/219
var hexSliceLookupTable = (function () {
var alphabet = '0123456789abcdef'
var table = new Array(256)
for (var i = 0; i < 16; ++i) {
var i16 = i * 16
for (var j = 0; j < 16; ++j) {
const hexSliceLookupTable = (function () {
const alphabet = '0123456789abcdef'
const table = new Array(256)
for (let i = 0; i < 16; ++i) {
const i16 = i * 16
for (let j = 0; j < 16; ++j) {
table[i16 + j] = alphabet[i] + alphabet[j]

@@ -1883,1 +2162,10 @@ }

})()
// Return not function with Error if BigInt not supported
function defineBigIntMethod (fn) {
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
}
function BufferBigIntNotDefined () {
throw new Error('BigInt not supported')
}
{
"name": "buffer",
"description": "Node.js Buffer API, for the browser",
"version": "5.7.0",
"version": "6.0.0",
"author": {

@@ -19,3 +19,3 @@ "name": "Feross Aboukhadijeh",

"base64-js": "^1.3.1",
"ieee754": "^1.1.13"
"ieee754": "^1.2.1"
},

@@ -28,3 +28,3 @@ "devDependencies": {

"hyperquest": "^2.1.3",
"is-buffer": "^2.0.4",
"is-buffer": "^2.0.5",
"is-nan": "^1.3.0",

@@ -35,3 +35,3 @@ "split": "^1.0.1",

"through2": "^4.0.2",
"uglify-js": "^3.11.3"
"uglify-js": "^3.11.5"
},

@@ -67,6 +67,6 @@ "homepage": "https://github.com/feross/buffer",

"test": "standard && node ./bin/test.js",
"test-browser-es5": "airtap -- test/*.js",
"test-browser-es5-local": "airtap --local -- test/*.js",
"test-browser-es6": "airtap -- test/*.js test/node/*.js",
"test-browser-es6-local": "airtap --local -- test/*.js test/node/*.js",
"test-browser-old": "airtap -- test/*.js",
"test-browser-old-local": "airtap --local -- test/*.js",
"test-browser-new": "airtap -- test/*.js test/node/*.js",
"test-browser-new-local": "airtap --local -- test/*.js test/node/*.js",
"test-node": "tape test/*.js test/node/*.js",

@@ -81,5 +81,2 @@ "update-authors": "./bin/update-authors.sh"

"perf/**/*.js"
],
"globals": [
"SharedArrayBuffer"
]

@@ -86,0 +83,0 @@ },

@@ -31,3 +31,3 @@ # buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

- Extremely small bundle size (**6.75KB minified + gzipped**, 51.9KB with comments)
- Excellent browser support (Chrome, Firefox, Edge, Safari 9+, IE 11, iOS 9+, Android, etc.)
- Excellent browser support (Chrome, Firefox, Edge, Safari 11+, iOS 11+, Android, etc.)
- Preserves Node API exactly, with one minor difference (see below)

@@ -34,0 +34,0 @@ - Square-bracket `buf[4]` notation works!

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc