bare-buffer
Advanced tools
Comparing version 2.7.1 to 3.0.0-0
@@ -13,6 +13,2 @@ type BufferEncoding = | ||
declare class Buffer extends Uint8Array { | ||
static Buffer: Buffer | ||
static poolSize: number | ||
compare( | ||
@@ -144,2 +140,6 @@ target: Buffer, | ||
declare namespace Buffer { | ||
export { Buffer } | ||
export let poolSize: number | ||
export function isBuffer(value: unknown): value is Buffer | ||
@@ -146,0 +146,0 @@ |
45
index.js
@@ -24,2 +24,40 @@ const constants = require('./lib/constants') | ||
constructor(arrayBuffer, offset, length, opts = {}) { | ||
if (typeof arrayBuffer === 'number') { | ||
opts = offset || {} | ||
const { uninitialized = false } = opts | ||
offset = 0 | ||
length = arrayBuffer | ||
if (length > constants.MAX_LENGTH) { | ||
throw new RangeError( | ||
`Buffer length must be at most ${constants.MAX_LENGTH}` | ||
) | ||
} | ||
arrayBuffer = uninitialized | ||
? binding.allocUnsafe(length) | ||
: binding.alloc(length) | ||
} else { | ||
if (length > constants.MAX_LENGTH) { | ||
throw new RangeError( | ||
`Buffer length must be at most ${constants.MAX_LENGTH}` | ||
) | ||
} | ||
if (typeof offset === 'object' && offset !== null) { | ||
opts = offset | ||
offset = 0 | ||
length = arrayBuffer.byteLength | ||
} else if (typeof length === 'length' && length !== null) { | ||
opts = length | ||
length = arrayBuffer.byteLength - offset | ||
} | ||
} | ||
super(arrayBuffer, offset, length) | ||
} | ||
[Symbol.species]() { | ||
@@ -538,8 +576,3 @@ return Buffer | ||
exports.allocUnsafe = function allocUnsafe(size) { | ||
binding.setZeroFillEnabled(0) | ||
try { | ||
return new Buffer(size) | ||
} finally { | ||
binding.setZeroFillEnabled(1) | ||
} | ||
return new Buffer(size, { uninitialized: true }) | ||
} | ||
@@ -546,0 +579,0 @@ |
module.exports = { | ||
MAX_LENGTH: 2 ** 32, // 4 GiB | ||
MAX_LENGTH: 2 ** 32 - 1, // 4 GiB | ||
MAX_STRING_LENGTH: 2 ** 28 - 16 // ~512 MiB, lowest common limit | ||
} |
{ | ||
"name": "bare-buffer", | ||
"version": "2.7.1", | ||
"version": "3.0.0-0", | ||
"description": "Native buffers for JavaScript", | ||
@@ -26,3 +26,3 @@ "exports": { | ||
"scripts": { | ||
"test": "prettier . --check && bare test/all.js" | ||
"test": "prettier . --check && bare test.js" | ||
}, | ||
@@ -39,2 +39,5 @@ "repository": { | ||
"homepage": "https://github.com/holepunchto/bare-buffer#readme", | ||
"engines": { | ||
"bare": ">=1.13.0" | ||
}, | ||
"devDependencies": { | ||
@@ -41,0 +44,0 @@ "brittle": "^3.1.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
748
697227
1