- Manipulate binary data like a boss, in all browsers!
- Super fast. Backed by Typed Arrays (`Uint8Array`/`ArrayBuffer`, not `Object`)
- 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)
- Square-bracket `buf[4]` notation works!
- Does not modify any browser prototypes or put anything on `window`
const airtapYmlPath = path.join(__dirname, '..', '.airtap.yml')
writeES5AirtapYml()
- cp.spawn('npm', ['run', 'test-browser-es5'], { stdio: 'inherit' })
+ cp.spawn('npm', ['run', 'test-browser-old'], { stdio: 'inherit' })
.on('close', function (code) {
if (code !== 0) process.exit(code)
writeES6AirtapYml()
- cp.spawn('npm', ['run', 'test-browser-es6'], { stdio: 'inherit' })
+ cp.spawn('npm', ['run', 'test-browser-new'], { stdio: 'inherit' })
.on('close', function (code) {
process.exit(code)
})
})
function writeES5AirtapYml () {
- fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-es5.yml')))
+ fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-old.yml')))
}
function writeES6AirtapYml () {
- fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-es6.yml')))
+ fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-new.yml')))
}
}
this[++offset] * 2 ** 16 +
last * 2 ** 24
- return BigInt(lo) + (BigInt(hi) << 32n)
+ return BigInt(lo) + (BigInt(hi) << BigInt(32))
})
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
this[++offset] * 2 ** 8 +
last
- return (BigInt(hi) << 32n) + BigInt(lo)
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo)
})
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
this[offset + 6] * 2 ** 16 +
(last << 24) // Overflow
- return (BigInt(val) << 32n) +
+ return (BigInt(val) << BigInt(32)) +
BigInt(first +
this[++offset] * 2 ** 8 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 8 +
this[++offset]
- return (BigInt(val) << 32n) +
+ return (BigInt(val) << BigInt(32)) +
BigInt(this[++offset] * 2 ** 24 +
this[++offset] * 2 ** 16 +
this[++offset] * 2 ** 8 +
function wrtBigUInt64LE (buf, value, offset, min, max) {
checkIntBI(value, min, max, buf, offset, 7)
- let lo = Number(value & 0xffffffffn)
+ let lo = Number(value & BigInt(0xffffffff))
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
- let hi = Number(value >> 32n & 0xffffffffn)
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
function wrtBigUInt64BE (buf, value, offset, min, max) {
checkIntBI(value, min, max, buf, offset, 7)
- let lo = Number(value & 0xffffffffn)
+ let lo = Number(value & BigInt(0xffffffff))
buf[offset + 7] = lo
lo = lo >> 8
buf[offset + 6] = lo
buf[offset + 5] = lo
lo = lo >> 8
buf[offset + 4] = lo
- let hi = Number(value >> 32n & 0xffffffffn)
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
buf[offset + 3] = hi
hi = hi >> 8
buf[offset + 2] = hi
}
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
- return wrtBigUInt64LE(this, value, offset, 0n, 0xffffffffffffffffn)
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
})
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
- return wrtBigUInt64BE(this, value, offset, 0n, 0xffffffffffffffffn)
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
})
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
}
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
- return wrtBigUInt64LE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn)
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
})
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
- return wrtBigUInt64BE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn)
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
})
function checkIEEE754 (buf, value, offset, ext, max, min) {
received = addNumericalSeparator(String(input))
} else if (typeof input === 'bigint') {
received = String(input)
- if (input > 2n ** 32n || input < -(2n ** 32n)) {
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
received = addNumericalSeparator(received)
}
received += 'n'
const n = typeof min === 'bigint' ? 'n' : ''
let range
if (byteLength > 3) {
- if (min === 0 || min === 0n) {
+ 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 ** ` +
],
"dependencies": {
"base64-js": "^1.3.1",
- "ieee754": "^1.1.13"
+ "ieee754": "^1.2.1"
},
"devDependencies": {
"airtap": "^3.0.0",
"browserify": "^17.0.0",
"concat-stream": "^2.0.0",
"hyperquest": "^2.1.3",
- "is-buffer": "^2.0.4",
+ "is-buffer": "^2.0.5",
"is-nan": "^1.3.0",
"split": "^1.0.1",
"standard": "*",
"tape": "^5.0.1",
"through2": "^4.0.2",
- "uglify-js": "^3.11.3"
+ "uglify-js": "^3.11.5"
},
"homepage": "https://github.com/feross/buffer",
"jspm": {
"perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js",
"size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c",
"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",
"update-authors": "./bin/update-authors.sh"
},
"standard": {
- "globals": [
- "BigInt"
- ],
"ignore": [
"test/node/**/*.js",
"test/common.js",
"test/_polyfill.js",
"perf/**/*.js"
- ],
- "globals": [
- "SharedArrayBuffer"
]
},
"funding": [