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,CAAC,CAAC;gBAC3C,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;gBAC9B,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;aAC7C,CAAC,CAAC;SACJ,CAAA;IACH,CAAC;CACF"} |
+1
-0
@@ -52,1 +52,2 @@ import util from 'node:util'; | ||
| } | ||
| //# sourceMappingURL=index.d.ts.map |
+413
-492
@@ -1,517 +0,438 @@ | ||
| import util from 'node:util' | ||
| const EMPTY_BUF = Buffer.alloc(0) | ||
| export class Slice { | ||
| buffer = EMPTY_BUF | ||
| byteOffset = 0 | ||
| byteLength = 0 | ||
| maxByteLength = 0 | ||
| static get EMPTY_BUF() { | ||
| return EMPTY_BUF | ||
| } | ||
| static from(buffer , byteOffset = 0, byteLength = buffer.byteLength - byteOffset) { | ||
| if (!(buffer instanceof Buffer)) { | ||
| throw new TypeError('buffer must be a Buffer') | ||
| import util from 'node:util'; | ||
| const EMPTY_BUF = Buffer.alloc(0); | ||
| export class Slice { | ||
| buffer = EMPTY_BUF; | ||
| byteOffset = 0; | ||
| byteLength = 0; | ||
| maxByteLength = 0; | ||
| static get EMPTY_BUF() { | ||
| return EMPTY_BUF; | ||
| } | ||
| if (byteOffset < 0 || !Number.isInteger(byteOffset)) { | ||
| throw new RangeError(`Invalid byteOffset: ${byteOffset}`) | ||
| static from(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) { | ||
| if (!(buffer instanceof Buffer)) { | ||
| throw new TypeError('buffer must be a Buffer'); | ||
| } | ||
| if (byteOffset < 0 || !Number.isInteger(byteOffset)) { | ||
| throw new RangeError(`Invalid byteOffset: ${byteOffset}`); | ||
| } | ||
| if (byteLength < 0 || !Number.isInteger(byteLength)) { | ||
| throw new RangeError(`Invalid byteLength: ${byteLength}`); | ||
| } | ||
| if (byteOffset + byteLength > buffer.byteLength) { | ||
| throw new RangeError(`byteOffset + byteLength (${byteOffset + byteLength}) exceeds buffer size (${buffer.byteLength})`); | ||
| } | ||
| return new Slice(buffer, byteOffset, byteLength); | ||
| } | ||
| if (byteLength < 0 || !Number.isInteger(byteLength)) { | ||
| throw new RangeError(`Invalid byteLength: ${byteLength}`) | ||
| constructor(buffer = Slice.EMPTY_BUF, byteOffset = 0, byteLength = buffer.byteLength, maxByteLength = byteLength) { | ||
| this.buffer = buffer; | ||
| this.byteOffset = byteOffset; | ||
| this.byteLength = byteLength; | ||
| this.maxByteLength = maxByteLength; | ||
| } | ||
| if (byteOffset + byteLength > buffer.byteLength) { | ||
| throw new RangeError( | ||
| `byteOffset + byteLength (${byteOffset + byteLength}) exceeds buffer size (${buffer.byteLength})`, | ||
| ) | ||
| reset() { | ||
| this.buffer = Slice.EMPTY_BUF; | ||
| this.byteOffset = 0; | ||
| this.byteLength = 0; | ||
| this.maxByteLength = 0; | ||
| } | ||
| return new Slice(buffer, byteOffset, byteLength) | ||
| } | ||
| constructor( | ||
| buffer = Slice.EMPTY_BUF, | ||
| byteOffset = 0, | ||
| byteLength = buffer.byteLength, | ||
| maxByteLength = byteLength, | ||
| ) { | ||
| this.buffer = buffer | ||
| this.byteOffset = byteOffset | ||
| this.byteLength = byteLength | ||
| this.maxByteLength = maxByteLength | ||
| } | ||
| reset() { | ||
| this.buffer = Slice.EMPTY_BUF | ||
| this.byteOffset = 0 | ||
| this.byteLength = 0 | ||
| this.maxByteLength = 0 | ||
| } | ||
| get length() { | ||
| return this.byteLength | ||
| } | ||
| copy( | ||
| target , | ||
| targetStart , | ||
| sourceStart , | ||
| sourceEnd , | ||
| ) { | ||
| const sliceEnd = this.byteOffset + this.byteLength | ||
| if (sourceStart === undefined) { | ||
| sourceStart = this.byteOffset | ||
| } else { | ||
| // Start offsets are validated (not clamped) so a negative offset can | ||
| // never resolve to a position before the slice and read adjacent | ||
| // (pool) memory. | ||
| if (sourceStart < 0 || sourceStart > this.byteLength || !Number.isInteger(sourceStart)) { | ||
| throw new RangeError(`Invalid sourceStart: ${sourceStart}`) | ||
| } | ||
| sourceStart += this.byteOffset | ||
| get length() { | ||
| return this.byteLength; | ||
| } | ||
| if (sourceEnd === undefined) { | ||
| sourceEnd = sliceEnd | ||
| } else { | ||
| sourceEnd += this.byteOffset | ||
| copy(target, targetStart, sourceStart, sourceEnd) { | ||
| const sliceEnd = this.byteOffset + this.byteLength; | ||
| if (sourceStart === undefined) { | ||
| sourceStart = this.byteOffset; | ||
| } | ||
| else { | ||
| // Start offsets are validated (not clamped) so a negative offset can | ||
| // never resolve to a position before the slice and read adjacent | ||
| // (pool) memory. | ||
| if (sourceStart < 0 || sourceStart > this.byteLength || !Number.isInteger(sourceStart)) { | ||
| throw new RangeError(`Invalid sourceStart: ${sourceStart}`); | ||
| } | ||
| sourceStart += this.byteOffset; | ||
| } | ||
| if (sourceEnd === undefined) { | ||
| sourceEnd = sliceEnd; | ||
| } | ||
| else { | ||
| sourceEnd += this.byteOffset; | ||
| } | ||
| // Clamp the end against the logical slice length so copy() cannot read | ||
| // past the slice's own end and leak adjacent (pool) memory. | ||
| if (sourceEnd > sliceEnd) { | ||
| sourceEnd = sliceEnd; | ||
| } | ||
| if (sourceEnd < sourceStart) { | ||
| sourceEnd = sourceStart; | ||
| } | ||
| if (target instanceof Slice) { | ||
| const targetEnd = target.byteOffset + target.byteLength; | ||
| if (targetStart === undefined) { | ||
| targetStart = target.byteOffset; | ||
| } | ||
| else { | ||
| if (targetStart < 0 || targetStart > target.byteLength || !Number.isInteger(targetStart)) { | ||
| throw new RangeError(`Invalid targetStart: ${targetStart}`); | ||
| } | ||
| targetStart += target.byteOffset; | ||
| } | ||
| target = target.buffer; | ||
| if (sourceEnd - sourceStart > targetEnd - targetStart) { | ||
| sourceEnd = sourceStart + (targetEnd - targetStart); | ||
| } | ||
| } | ||
| if (sourceStart === targetStart && | ||
| this.buffer.buffer === target.buffer && | ||
| this.buffer.byteOffset === target.byteOffset) { | ||
| return sourceEnd - sourceStart; | ||
| } | ||
| return this.buffer.copy(target, targetStart, sourceStart, sourceEnd); | ||
| } | ||
| // Clamp the end against the logical slice length so copy() cannot read | ||
| // past the slice's own end and leak adjacent (pool) memory. | ||
| if (sourceEnd > sliceEnd) { | ||
| sourceEnd = sliceEnd | ||
| compare(target, targetStart, targetEnd, sourceStart, sourceEnd) { | ||
| if (target === this && | ||
| targetStart === undefined && | ||
| targetEnd === undefined && | ||
| sourceStart === undefined && | ||
| sourceEnd === undefined) { | ||
| return 0; | ||
| } | ||
| const sliceEnd = this.byteOffset + this.byteLength; | ||
| if (target instanceof Slice) { | ||
| const targetSliceEnd = target.byteOffset + target.byteLength; | ||
| if (targetStart === undefined) { | ||
| targetStart = target.byteOffset; | ||
| } | ||
| else { | ||
| if (targetStart < 0 || targetStart > target.byteLength || !Number.isInteger(targetStart)) { | ||
| throw new RangeError(`Invalid targetStart: ${targetStart}`); | ||
| } | ||
| targetStart += target.byteOffset; | ||
| } | ||
| if (targetEnd === undefined) { | ||
| targetEnd = targetSliceEnd; | ||
| } | ||
| else { | ||
| targetEnd += target.byteOffset; | ||
| } | ||
| if (targetEnd > targetSliceEnd) { | ||
| targetEnd = targetSliceEnd; | ||
| } | ||
| if (targetEnd < targetStart) { | ||
| targetEnd = targetStart; | ||
| } | ||
| target = target.buffer; | ||
| } | ||
| if (sourceStart === undefined) { | ||
| sourceStart = this.byteOffset; | ||
| } | ||
| else { | ||
| if (sourceStart < 0 || sourceStart > this.byteLength || !Number.isInteger(sourceStart)) { | ||
| throw new RangeError(`Invalid sourceStart: ${sourceStart}`); | ||
| } | ||
| sourceStart += this.byteOffset; | ||
| } | ||
| if (sourceEnd === undefined) { | ||
| sourceEnd = sliceEnd; | ||
| } | ||
| else { | ||
| sourceEnd += this.byteOffset; | ||
| } | ||
| if (sourceEnd > sliceEnd) { | ||
| sourceEnd = sliceEnd; | ||
| } | ||
| if (sourceEnd < sourceStart) { | ||
| sourceEnd = sourceStart; | ||
| } | ||
| return this.buffer.compare(target, targetStart, targetEnd, sourceStart, sourceEnd); | ||
| } | ||
| if (sourceEnd < sourceStart) { | ||
| sourceEnd = sourceStart | ||
| write(string, offset, length, encoding) { | ||
| const sliceEnd = this.byteOffset + this.byteLength; | ||
| if (offset === undefined) { | ||
| offset = this.byteOffset; | ||
| } | ||
| else { | ||
| if (offset < 0 || offset > this.byteLength || !Number.isInteger(offset)) { | ||
| throw new RangeError(`Invalid offset: ${offset}`); | ||
| } | ||
| offset += this.byteOffset; | ||
| } | ||
| const available = sliceEnd - offset; | ||
| if (length === undefined) { | ||
| length = available; | ||
| } | ||
| else { | ||
| if (length < 0 || !Number.isInteger(length)) { | ||
| throw new RangeError(`Invalid length: ${length}`); | ||
| } | ||
| if (length > available) { | ||
| length = available; | ||
| } | ||
| } | ||
| return this.buffer.write(string, offset, length, encoding); | ||
| } | ||
| if (target instanceof Slice) { | ||
| const targetEnd = target.byteOffset + target.byteLength | ||
| if (targetStart === undefined) { | ||
| targetStart = target.byteOffset | ||
| } else { | ||
| if (targetStart < 0 || targetStart > target.byteLength || !Number.isInteger(targetStart)) { | ||
| throw new RangeError(`Invalid targetStart: ${targetStart}`) | ||
| set(source, offset) { | ||
| if (source == null) { | ||
| return; | ||
| } | ||
| targetStart += target.byteOffset | ||
| } | ||
| target = target.buffer | ||
| if (sourceEnd - sourceStart > targetEnd - targetStart) { | ||
| sourceEnd = sourceStart + (targetEnd - targetStart) | ||
| } | ||
| if (offset === undefined) { | ||
| offset = this.byteOffset; | ||
| } | ||
| else { | ||
| // Validate (not clamp): a negative offset would resolve to a position | ||
| // before the slice and corrupt adjacent (pool) memory. | ||
| if (offset < 0 || offset > this.byteLength || !Number.isInteger(offset)) { | ||
| throw new RangeError(`Invalid offset: ${offset}`); | ||
| } | ||
| offset += this.byteOffset; | ||
| } | ||
| const available = this.byteOffset + this.byteLength - offset; | ||
| if (available <= 0) { | ||
| return; | ||
| } | ||
| const end = source.byteLength < available ? source.byteLength : available; | ||
| source.copy(this.buffer, offset, 0, end); | ||
| } | ||
| if ( | ||
| sourceStart === targetStart && | ||
| this.buffer.buffer === target.buffer && | ||
| this.buffer.byteOffset === target.byteOffset | ||
| ) { | ||
| return sourceEnd - sourceStart | ||
| at(index) { | ||
| if (!Number.isInteger(index) || index >= this.byteLength || index < -this.byteLength) { | ||
| throw new RangeError(`Index out of range: ${index}`); | ||
| } | ||
| return index >= 0 | ||
| ? this.buffer[this.byteOffset + index] | ||
| : this.buffer[this.byteOffset + this.byteLength + index]; | ||
| } | ||
| return this.buffer.copy(target, targetStart, sourceStart, sourceEnd) | ||
| } | ||
| compare( | ||
| target , | ||
| targetStart , | ||
| targetEnd , | ||
| sourceStart , | ||
| sourceEnd , | ||
| ) { | ||
| if ( | ||
| target === this && | ||
| targetStart === undefined && | ||
| targetEnd === undefined && | ||
| sourceStart === undefined && | ||
| sourceEnd === undefined | ||
| ) { | ||
| return 0 | ||
| test(expr) { | ||
| return expr.test(this.buffer, this.byteOffset, this.byteLength); | ||
| } | ||
| const sliceEnd = this.byteOffset + this.byteLength | ||
| if (target instanceof Slice) { | ||
| const targetSliceEnd = target.byteOffset + target.byteLength | ||
| if (targetStart === undefined) { | ||
| targetStart = target.byteOffset | ||
| } else { | ||
| if (targetStart < 0 || targetStart > target.byteLength || !Number.isInteger(targetStart)) { | ||
| throw new RangeError(`Invalid targetStart: ${targetStart}`) | ||
| toString(encoding, start, end) { | ||
| const sliceEnd = this.byteOffset + this.byteLength; | ||
| if (start === undefined) { | ||
| start = this.byteOffset; | ||
| } | ||
| targetStart += target.byteOffset | ||
| } | ||
| if (targetEnd === undefined) { | ||
| targetEnd = targetSliceEnd | ||
| } else { | ||
| targetEnd += target.byteOffset | ||
| } | ||
| if (targetEnd > targetSliceEnd) { | ||
| targetEnd = targetSliceEnd | ||
| } | ||
| if (targetEnd < targetStart) { | ||
| targetEnd = targetStart | ||
| } | ||
| target = target.buffer | ||
| else { | ||
| if (start < 0 || start > this.byteLength || !Number.isInteger(start)) { | ||
| throw new RangeError(`Invalid start: ${start}`); | ||
| } | ||
| start += this.byteOffset; | ||
| } | ||
| if (end === undefined) { | ||
| end = sliceEnd; | ||
| } | ||
| else { | ||
| end += this.byteOffset; | ||
| } | ||
| if (end > sliceEnd) { | ||
| end = sliceEnd; | ||
| } | ||
| if (end < start) { | ||
| end = start; | ||
| } | ||
| return this.buffer.toString(encoding, start, end); | ||
| } | ||
| if (sourceStart === undefined) { | ||
| sourceStart = this.byteOffset | ||
| } else { | ||
| if (sourceStart < 0 || sourceStart > this.byteLength || !Number.isInteger(sourceStart)) { | ||
| throw new RangeError(`Invalid sourceStart: ${sourceStart}`) | ||
| } | ||
| sourceStart += this.byteOffset | ||
| toBuffer(start, end) { | ||
| const sliceEnd = this.byteOffset + this.byteLength; | ||
| if (start === undefined) { | ||
| start = this.byteOffset; | ||
| } | ||
| else { | ||
| if (start < 0 || start > this.byteLength || !Number.isInteger(start)) { | ||
| throw new RangeError(`Invalid start: ${start}`); | ||
| } | ||
| start += this.byteOffset; | ||
| } | ||
| if (end === undefined) { | ||
| end = sliceEnd; | ||
| } | ||
| else { | ||
| end += this.byteOffset; | ||
| } | ||
| if (end > sliceEnd) { | ||
| end = sliceEnd; | ||
| } | ||
| if (end < start) { | ||
| end = start; | ||
| } | ||
| return start === 0 && end === this.buffer.byteLength | ||
| ? this.buffer | ||
| : this.buffer.subarray(start, end); | ||
| } | ||
| if (sourceEnd === undefined) { | ||
| sourceEnd = sliceEnd | ||
| } else { | ||
| sourceEnd += this.byteOffset | ||
| get [Symbol.toStringTag]() { | ||
| return 'Slice'; | ||
| } | ||
| if (sourceEnd > sliceEnd) { | ||
| sourceEnd = sliceEnd | ||
| [util.inspect.custom]() { | ||
| const MAX_BYTES = 32; | ||
| const len = this.byteLength; | ||
| // A malformed slice (a NaN/non-finite/fractional/negative/out-of-bounds | ||
| // byteOffset or byteLength) is exactly the state a developer inspects while | ||
| // debugging pool corruption — inspect must never throw on it. Coerce | ||
| // byteOffset to a safe integer index in [0, buffer.byteLength]: the | ||
| // `>= 0` test is false for NaN and -Infinity (→ 0), Math.floor truncates a | ||
| // fractional offset, and Math.min caps Infinity/oversize at the buffer end | ||
| // (available 0). Every buffer access below is then guaranteed in-bounds and | ||
| // begin + shown <= buffer.byteLength holds. | ||
| const bufferLength = this.buffer.byteLength; | ||
| const begin = this.byteOffset >= 0 ? Math.min(Math.floor(this.byteOffset), bufferLength) : 0; | ||
| const cap = bufferLength - begin; | ||
| const safeLen = len > 0 ? (len < cap ? len : cap) : 0; | ||
| const shown = safeLen < MAX_BYTES ? safeLen : MAX_BYTES; | ||
| let hex = ''; | ||
| for (let i = 0; i < shown; i++) { | ||
| if (i !== 0) { | ||
| hex += ' '; | ||
| } | ||
| hex += this.buffer[begin + i].toString(16).padStart(2, '0'); | ||
| } | ||
| if (shown < len) { | ||
| hex += ` ... (${len - shown} more)`; | ||
| } | ||
| const str = this.buffer.toString('utf8', begin, begin + shown); | ||
| const truncated = shown < len ? '…' : ''; | ||
| return `Slice(${len}): "${str}${truncated}" <${hex}>`; | ||
| } | ||
| if (sourceEnd < sourceStart) { | ||
| sourceEnd = sourceStart | ||
| } | ||
| return this.buffer.compare(target, targetStart, targetEnd, sourceStart, sourceEnd) | ||
| } | ||
| write(string , offset , length , encoding ) { | ||
| const sliceEnd = this.byteOffset + this.byteLength | ||
| if (offset === undefined) { | ||
| offset = this.byteOffset | ||
| } else { | ||
| if (offset < 0 || offset > this.byteLength || !Number.isInteger(offset)) { | ||
| throw new RangeError(`Invalid offset: ${offset}`) | ||
| } | ||
| offset += this.byteOffset | ||
| } | ||
| const available = sliceEnd - offset | ||
| if (length === undefined) { | ||
| length = available | ||
| } else { | ||
| if (length < 0 || !Number.isInteger(length)) { | ||
| throw new RangeError(`Invalid length: ${length}`) | ||
| } | ||
| if (length > available) { | ||
| length = available | ||
| } | ||
| } | ||
| return this.buffer.write(string, offset, length, encoding) | ||
| } | ||
| set(source , offset ) { | ||
| if (source == null) { | ||
| return | ||
| } | ||
| if (offset === undefined) { | ||
| offset = this.byteOffset | ||
| } else { | ||
| // Validate (not clamp): a negative offset would resolve to a position | ||
| // before the slice and corrupt adjacent (pool) memory. | ||
| if (offset < 0 || offset > this.byteLength || !Number.isInteger(offset)) { | ||
| throw new RangeError(`Invalid offset: ${offset}`) | ||
| } | ||
| offset += this.byteOffset | ||
| } | ||
| const available = this.byteOffset + this.byteLength - offset | ||
| if (available <= 0) { | ||
| return | ||
| } | ||
| const end = source.byteLength < available ? source.byteLength : available | ||
| source.copy(this.buffer, offset, 0, end) | ||
| } | ||
| at(index ) { | ||
| if (!Number.isInteger(index) || index >= this.byteLength || index < -this.byteLength) { | ||
| throw new RangeError(`Index out of range: ${index}`) | ||
| } | ||
| return index >= 0 | ||
| ? this.buffer[this.byteOffset + index] | ||
| : this.buffer[this.byteOffset + this.byteLength + index] | ||
| } | ||
| test(expr | ||
| ) { | ||
| return expr.test(this.buffer, this.byteOffset, this.byteLength) | ||
| } | ||
| toString(encoding , start , end ) { | ||
| const sliceEnd = this.byteOffset + this.byteLength | ||
| if (start === undefined) { | ||
| start = this.byteOffset | ||
| } else { | ||
| if (start < 0 || start > this.byteLength || !Number.isInteger(start)) { | ||
| throw new RangeError(`Invalid start: ${start}`) | ||
| } | ||
| start += this.byteOffset | ||
| } | ||
| if (end === undefined) { | ||
| end = sliceEnd | ||
| } else { | ||
| end += this.byteOffset | ||
| } | ||
| if (end > sliceEnd) { | ||
| end = sliceEnd | ||
| } | ||
| if (end < start) { | ||
| end = start | ||
| } | ||
| return this.buffer.toString(encoding, start, end) | ||
| } | ||
| toBuffer(start , end ) { | ||
| const sliceEnd = this.byteOffset + this.byteLength | ||
| if (start === undefined) { | ||
| start = this.byteOffset | ||
| } else { | ||
| if (start < 0 || start > this.byteLength || !Number.isInteger(start)) { | ||
| throw new RangeError(`Invalid start: ${start}`) | ||
| } | ||
| start += this.byteOffset | ||
| } | ||
| if (end === undefined) { | ||
| end = sliceEnd | ||
| } else { | ||
| end += this.byteOffset | ||
| } | ||
| if (end > sliceEnd) { | ||
| end = sliceEnd | ||
| } | ||
| if (end < start) { | ||
| end = start | ||
| } | ||
| return start === 0 && end === this.buffer.byteLength | ||
| ? this.buffer | ||
| : this.buffer.subarray(start, end) | ||
| } | ||
| get [Symbol.toStringTag]() { | ||
| return 'Slice' | ||
| } | ||
| [util.inspect.custom]() { | ||
| const MAX_BYTES = 32 | ||
| const len = this.byteLength | ||
| // Never read past the underlying buffer. A malformed slice (byteOffset / | ||
| // byteLength extending beyond the buffer) is exactly the state a developer | ||
| // inspects while debugging pool corruption — inspect must not throw on it. | ||
| const available = this.buffer.byteLength - this.byteOffset | ||
| const safeLen = available > 0 ? (len < available ? len : available) : 0 | ||
| const shown = safeLen < MAX_BYTES ? safeLen : MAX_BYTES | ||
| let hex = '' | ||
| for (let i = 0; i < shown; i++) { | ||
| if (i !== 0) { | ||
| hex += ' ' | ||
| } | ||
| hex += this.buffer[this.byteOffset + i].toString(16).padStart(2, '0') | ||
| } | ||
| if (shown < len) { | ||
| hex += ` ... (${len - shown} more)` | ||
| } | ||
| const str = this.buffer.toString('utf8', this.byteOffset, this.byteOffset + shown) | ||
| const truncated = shown < len ? '…' : '' | ||
| return `Slice(${len}): "${str}${truncated}" <${hex}>` | ||
| } | ||
| } | ||
| export class PoolAllocator { | ||
| #size = 0 | ||
| #padding = 0 | ||
| #poolsBucket = [] | ||
| #poolsBucketUsed = [] | ||
| #poolBuffer | ||
| #poolOffset = 0 | ||
| #poolSize = 0 | ||
| #poolCount = 0 | ||
| constructor( | ||
| poolTotalOrBuffer = 128 * | ||
| 1024 * | ||
| 1024, | ||
| ) { | ||
| if (typeof poolTotalOrBuffer === 'number') { | ||
| if (!Number.isInteger(poolTotalOrBuffer) || poolTotalOrBuffer < 0) { | ||
| throw new RangeError(`Invalid pool size: ${poolTotalOrBuffer}`) | ||
| } | ||
| this.#poolBuffer = Buffer.allocUnsafeSlow(poolTotalOrBuffer) | ||
| } else if (poolTotalOrBuffer instanceof Buffer) { | ||
| this.#poolBuffer = poolTotalOrBuffer | ||
| } else if (ArrayBuffer.isView(poolTotalOrBuffer)) { | ||
| this.#poolBuffer = Buffer.from( | ||
| poolTotalOrBuffer.buffer, | ||
| poolTotalOrBuffer.byteOffset, | ||
| poolTotalOrBuffer.byteLength, | ||
| ) | ||
| } else if ( | ||
| poolTotalOrBuffer instanceof ArrayBuffer || | ||
| poolTotalOrBuffer instanceof SharedArrayBuffer | ||
| ) { | ||
| this.#poolBuffer = Buffer.from(poolTotalOrBuffer) | ||
| } else { | ||
| throw new TypeError( | ||
| 'Invalid poolTotalOrBuffer: must be a Buffer, ArrayBufferView, ArrayBuffer, SharedArrayBuffer, or number', | ||
| ) | ||
| #size = 0; | ||
| #padding = 0; | ||
| #poolsBucket = []; | ||
| #poolsBucketUsed = []; | ||
| #poolBuffer; | ||
| #poolOffset = 0; | ||
| #poolSize = 0; | ||
| #poolCount = 0; | ||
| constructor(poolTotalOrBuffer = 128 * | ||
| 1024 * | ||
| 1024) { | ||
| if (typeof poolTotalOrBuffer === 'number') { | ||
| if (!Number.isInteger(poolTotalOrBuffer) || poolTotalOrBuffer < 0) { | ||
| throw new RangeError(`Invalid pool size: ${poolTotalOrBuffer}`); | ||
| } | ||
| this.#poolBuffer = Buffer.allocUnsafeSlow(poolTotalOrBuffer); | ||
| } | ||
| else if (poolTotalOrBuffer instanceof Buffer) { | ||
| this.#poolBuffer = poolTotalOrBuffer; | ||
| } | ||
| else if (ArrayBuffer.isView(poolTotalOrBuffer)) { | ||
| this.#poolBuffer = Buffer.from(poolTotalOrBuffer.buffer, poolTotalOrBuffer.byteOffset, poolTotalOrBuffer.byteLength); | ||
| } | ||
| else if (poolTotalOrBuffer instanceof ArrayBuffer || | ||
| poolTotalOrBuffer instanceof SharedArrayBuffer) { | ||
| this.#poolBuffer = Buffer.from(poolTotalOrBuffer); | ||
| } | ||
| else { | ||
| throw new TypeError('Invalid poolTotalOrBuffer: must be a Buffer, ArrayBufferView, ArrayBuffer, SharedArrayBuffer, or number'); | ||
| } | ||
| for (let n = 0; 2 ** n <= 256 * 1024; n++) { | ||
| this.#poolsBucket.push([]); | ||
| this.#poolsBucketUsed.push(0); | ||
| } | ||
| } | ||
| for (let n = 0; 2 ** n <= 256 * 1024; n++) { | ||
| this.#poolsBucket.push([]) | ||
| this.#poolsBucketUsed.push(0) | ||
| get size() { | ||
| return this.#size; | ||
| } | ||
| } | ||
| get size() { | ||
| return this.#size | ||
| } | ||
| isFromPool(slice ) { | ||
| return slice != null && slice.buffer === this.#poolBuffer | ||
| } | ||
| realloc(slice , byteLength ) { | ||
| if (typeof slice === 'number') { | ||
| byteLength = slice | ||
| slice = new Slice() | ||
| isFromPool(slice) { | ||
| return slice != null && slice.buffer === this.#poolBuffer; | ||
| } | ||
| if (byteLength == null || !Number.isInteger(byteLength) || byteLength < 0) { | ||
| throw new TypeError(`Invalid byteLength: ${byteLength}`) | ||
| realloc(slice, byteLength) { | ||
| if (typeof slice === 'number') { | ||
| byteLength = slice; | ||
| slice = new Slice(); | ||
| } | ||
| if (byteLength == null || !Number.isInteger(byteLength) || byteLength < 0) { | ||
| throw new TypeError(`Invalid byteLength: ${byteLength}`); | ||
| } | ||
| // 2^30 is the largest power-of-two that fits a 32-bit signed int; a | ||
| // larger request overflows `1 << dstIdx` to a negative bucket size. | ||
| if (byteLength > 1 << 30) { | ||
| throw new RangeError(`byteLength too large: ${byteLength} (max ${1 << 30})`); | ||
| } | ||
| if (slice.byteLength === byteLength) { | ||
| return slice; | ||
| } | ||
| // Ceil to nearest power of two — the destination bucket and its byte size. | ||
| const dstIdx = byteLength <= 8 ? 3 : 32 - Math.clz32(byteLength - 1); | ||
| const maxByteLength = 1 << dstIdx; | ||
| if (slice.buffer === this.#poolBuffer) { | ||
| const srcMaxByteLength = slice.maxByteLength; | ||
| // Same-bucket resize is the hot path: just update the logical length and | ||
| // adjust padding by the delta — no bucket bookkeeping, no second clz32, | ||
| // no net change to #size. A free (byteLength === 0) is deliberately | ||
| // excluded so it always falls through to the free-list path below: | ||
| // byteLength 0 maps to dstIdx 3 / maxByteLength 8, which would otherwise | ||
| // match a live bucket-3 slot here and "resize" it to 0 — leaking the slot | ||
| // (never returned to the free list, still counted in #size/#poolSize). | ||
| if (byteLength !== 0 && srcMaxByteLength === maxByteLength) { | ||
| this.#padding += slice.byteLength - byteLength; | ||
| slice.byteLength = byteLength; | ||
| return slice; | ||
| } | ||
| const srcIdx = 32 - Math.clz32(srcMaxByteLength - 1); | ||
| // Corruption tripwire for a foreign/double-freed slice. maxByteLength must | ||
| // be a power of two that maps to a real pool bucket — index in | ||
| // [3, poolsBucket.length). The pool never hands out a slot below bucket 3 | ||
| // (8 bytes), so a smaller power of two (1/2/4 → srcIdx 0/1/2) is just as | ||
| // corrupt as an oversized one (e.g. 2^20 → srcIdx 20, out of range): | ||
| // `=== 1 << srcIdx` alone passes both, after which the bucket bookkeeping | ||
| // below would drive an always-empty bucket's `used` count negative (or | ||
| // index a non-existent bucket) and drift #size/#poolSize. | ||
| if (srcMaxByteLength !== 1 << srcIdx || srcIdx < 3 || srcIdx >= this.#poolsBucket.length) { | ||
| throw new Error(`Invalid pool state`); | ||
| } | ||
| this.#size -= srcMaxByteLength; | ||
| this.#padding -= srcMaxByteLength - slice.byteLength; | ||
| this.#poolsBucket[srcIdx].push(slice.byteOffset); | ||
| this.#poolsBucketUsed[srcIdx] -= 1; | ||
| this.#poolSize -= srcMaxByteLength; | ||
| } | ||
| slice.reset(); | ||
| if (byteLength === 0) { | ||
| return slice; | ||
| } | ||
| if (dstIdx < this.#poolsBucket.length && this.#poolsBucket[dstIdx].length) { | ||
| slice.buffer = this.#poolBuffer; | ||
| slice.byteOffset = this.#poolsBucket[dstIdx].pop(); | ||
| slice.byteLength = byteLength; | ||
| slice.maxByteLength = maxByteLength; | ||
| this.#poolsBucketUsed[dstIdx] += 1; | ||
| this.#poolSize += maxByteLength; | ||
| this.#size += maxByteLength; | ||
| this.#padding += maxByteLength - byteLength; | ||
| } | ||
| else if (dstIdx < this.#poolsBucket.length && | ||
| this.#poolOffset + maxByteLength <= this.#poolBuffer.byteLength) { | ||
| slice.buffer = this.#poolBuffer; | ||
| slice.byteOffset = this.#poolOffset; | ||
| slice.byteLength = byteLength; | ||
| slice.maxByteLength = maxByteLength; | ||
| this.#poolOffset += maxByteLength; | ||
| this.#poolCount += 1; | ||
| this.#poolsBucketUsed[dstIdx] += 1; | ||
| this.#poolSize += maxByteLength; | ||
| this.#size += maxByteLength; | ||
| this.#padding += maxByteLength - byteLength; | ||
| } | ||
| else { | ||
| slice.buffer = Buffer.allocUnsafeSlow(byteLength); | ||
| slice.byteOffset = 0; | ||
| slice.byteLength = byteLength; | ||
| slice.maxByteLength = byteLength; | ||
| } | ||
| return slice; | ||
| } | ||
| // 2^30 is the largest power-of-two that fits a 32-bit signed int; a | ||
| // larger request overflows `1 << dstIdx` to a negative bucket size. | ||
| if (byteLength > 1 << 30) { | ||
| throw new RangeError(`byteLength too large: ${byteLength} (max ${1 << 30})`) | ||
| get stats() { | ||
| return { | ||
| size: this.#size, | ||
| padding: this.#padding, | ||
| ratio: this.#size > this.#padding ? this.#size / (this.#size - this.#padding) : 1, | ||
| poolTotal: this.#poolBuffer.byteLength, | ||
| poolUsed: this.#poolOffset, | ||
| poolSize: this.#poolSize, | ||
| poolCount: this.#poolCount, | ||
| buckets: this.#poolsBucket.map((pool, i) => ({ | ||
| free: pool.length, | ||
| used: this.#poolsBucketUsed[i], | ||
| size: pool.length + this.#poolsBucketUsed[i], | ||
| })), | ||
| }; | ||
| } | ||
| if (slice.byteLength === byteLength) { | ||
| return slice | ||
| } | ||
| // Ceil to nearest power of two. | ||
| const dstIdx = byteLength <= 8 ? 3 : 32 - Math.clz32(byteLength - 1) | ||
| if (slice.buffer === this.#poolBuffer) { | ||
| const srcIdx = 32 - Math.clz32(slice.maxByteLength - 1) | ||
| if (slice.maxByteLength !== 1 << srcIdx) { | ||
| throw new Error(`Invalid pool state`) | ||
| } | ||
| this.#size -= slice.maxByteLength | ||
| this.#padding -= slice.maxByteLength - slice.byteLength | ||
| if (srcIdx === dstIdx) { | ||
| slice.byteLength = byteLength | ||
| this.#size += slice.maxByteLength | ||
| this.#padding += slice.maxByteLength - slice.byteLength | ||
| return slice | ||
| } | ||
| this.#poolsBucket[srcIdx].push(slice.byteOffset) | ||
| this.#poolsBucketUsed[srcIdx] -= 1 | ||
| this.#poolSize -= slice.maxByteLength | ||
| } | ||
| slice.reset() | ||
| if (byteLength === 0) { | ||
| return slice | ||
| } | ||
| const maxByteLength = 1 << dstIdx | ||
| if (dstIdx < this.#poolsBucket.length && this.#poolsBucket[dstIdx].length) { | ||
| slice.buffer = this.#poolBuffer | ||
| slice.byteOffset = this.#poolsBucket[dstIdx].pop() | ||
| slice.byteLength = byteLength | ||
| slice.maxByteLength = maxByteLength | ||
| this.#poolsBucketUsed[dstIdx] += 1 | ||
| this.#poolSize += maxByteLength | ||
| this.#size += maxByteLength | ||
| this.#padding += maxByteLength - byteLength | ||
| } else if ( | ||
| dstIdx < this.#poolsBucket.length && | ||
| this.#poolOffset + maxByteLength <= this.#poolBuffer.byteLength | ||
| ) { | ||
| slice.buffer = this.#poolBuffer | ||
| slice.byteOffset = this.#poolOffset | ||
| slice.byteLength = byteLength | ||
| slice.maxByteLength = maxByteLength | ||
| this.#poolOffset += maxByteLength | ||
| this.#poolCount += 1 | ||
| this.#poolsBucketUsed[dstIdx] += 1 | ||
| this.#poolSize += maxByteLength | ||
| this.#size += maxByteLength | ||
| this.#padding += maxByteLength - byteLength | ||
| } else { | ||
| slice.buffer = Buffer.allocUnsafeSlow(byteLength) | ||
| slice.byteOffset = 0 | ||
| slice.byteLength = byteLength | ||
| slice.maxByteLength = byteLength | ||
| } | ||
| return slice | ||
| } | ||
| get stats() { | ||
| return { | ||
| size: this.#size, | ||
| padding: this.#padding, | ||
| ratio: this.#size > this.#padding ? this.#size / (this.#size - this.#padding) : 1, | ||
| poolTotal: this.#poolBuffer.byteLength, | ||
| poolUsed: this.#poolOffset, | ||
| poolSize: this.#poolSize, | ||
| poolCount: this.#poolCount, | ||
| buckets: this.#poolsBucket.map((pool, i) => ({ | ||
| free: pool.length, | ||
| used: this.#poolsBucketUsed[i], | ||
| size: pool.length + this.#poolsBucketUsed[i], | ||
| })), | ||
| } | ||
| } | ||
| } | ||
| //# sourceMappingURL=index.js.map |
+2
-3
| { | ||
| "name": "@nxtedition/slice", | ||
| "version": "1.1.10", | ||
| "version": "1.1.11", | ||
| "type": "module", | ||
@@ -17,3 +17,3 @@ "main": "lib/index.js", | ||
| "scripts": { | ||
| "build": "rimraf lib && tsc -p tsconfig.build.json && amaroc ./src/index.ts && mv src/index.js lib/", | ||
| "build": "rimraf lib && tsc -p tsconfig.build.json", | ||
| "prepublishOnly": "yarn build", | ||
@@ -28,3 +28,2 @@ "typecheck": "tsc --noEmit", | ||
| "@types/node": "^25.5.0", | ||
| "amaroc": "^1.0.1", | ||
| "oxlint-tsgolint": "^0.17.0", | ||
@@ -31,0 +30,0 @@ "rimraf": "^6.1.3", |
+11
-5
@@ -92,4 +92,8 @@ # @nxtedition/slice | ||
| Creates a new slice. All parameters are optional — defaults to an empty slice. | ||
| Creates a new slice. All parameters are optional — defaults to an empty slice. The constructor does **no** validation; pass only consistent values, or use `Slice.from` for a checked construction. | ||
| #### `Slice.from(buffer: Buffer, byteOffset?: number, byteLength?: number): Slice` | ||
| Validated factory for wrapping an existing `Buffer`. `byteOffset` defaults to `0` and `byteLength` to the remaining bytes (`buffer.byteLength - byteOffset`). Throws `TypeError` if `buffer` is not a `Buffer`, and `RangeError` if `byteOffset`/`byteLength` are negative, non-integer, or `byteOffset + byteLength` exceeds the buffer. Prefer this over the bare constructor when the inputs are untrusted. | ||
| #### Properties | ||
@@ -100,3 +104,3 @@ | ||
| - `byteLength: number` — Current length in bytes | ||
| - `maxByteLength: number` — Maximum capacity in bytes | ||
| - `maxByteLength: number` — For a pool-allocated slice, the power-of-2 bucket capacity (always `>= byteLength`). For a manually-constructed slice it defaults to `byteLength` and is purely informational: no method bounds writes against it — reads and writes are validated/clamped against `byteLength`. | ||
| - `length: number` — Alias for `byteLength` | ||
@@ -106,3 +110,3 @@ | ||
| - `reset(): void` — Clear the slice back to empty state. **Note:** this does not return the slot to the `PoolAllocator` — you must call `realloc(slice, 0)` to free pool memory. | ||
| - `reset(): void` — Clear the slice back to empty state. **Note:** this does not return the slot to the `PoolAllocator`. To free pool memory call `realloc(slice, 0)` — and do **not** `reset()` first: `reset()` detaches the slice from the pool buffer, so a subsequent `realloc(slice, 0)` can no longer locate the slot and the slot leaks. | ||
| - `copy(target: Uint8Array | Slice, targetStart?: number, sourceStart?: number, sourceEnd?: number): number` — Copy data to a `Uint8Array`/`Buffer` or `Slice`. Returns bytes copied. | ||
@@ -123,4 +127,6 @@ - `compare(target: Uint8Array | Slice, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1` — Compare with a `Uint8Array`/`Buffer` or `Slice` | ||
| - **Start/offset arguments are validated** — `set`'s `offset`, `copy`/`compare`'s `sourceStart`/`targetStart`, `toString`/`toBuffer`'s `start`, `write`'s `offset`/`length`, and `at`'s `index` must be in-range integers. Out-of-range or non-integer values throw `RangeError`. This prevents a negative offset from resolving to a position **before** the slice and reading/writing adjacent (pool) memory. | ||
| - **Start/offset arguments are validated** — `set`'s `offset`, `copy`/`compare`'s `sourceStart`/`targetStart`, `toString`/`toBuffer`'s `start`, `write`'s `offset`, and `at`'s `index` must be in-range integers. Out-of-range or non-integer values throw `RangeError`. This prevents a negative offset from resolving to a position **before** the slice and reading/writing adjacent (pool) memory. | ||
| - **End arguments are clamped** — `sourceEnd`/`targetEnd`/`end` are clamped to the slice's logical length (matching `Buffer`'s lenient end-of-range behavior), so over-long ranges never read past the slice's end. | ||
| - **`write`'s `length` is hybrid** — a negative or non-integer `length` throws `RangeError`, but a too-large `length` is clamped to the bytes available in the slice (it behaves like an end argument, not a strict start argument). | ||
| - For a raw `Buffer`/`Uint8Array` target, `targetStart`/`targetEnd` (and a non-`Slice` `compare` target's range) are passed straight through to the underlying `Buffer` method, so they follow `Buffer`'s own coercion/validation rather than the rules above. | ||
@@ -144,3 +150,3 @@ #### Static | ||
| - `realloc(byteLength: number): Slice` — Allocate a fresh slice. | ||
| - `realloc(slice: Slice, byteLength: number): Slice` — Resize a slice, or free it by passing `0`. **Contents are not preserved** — `realloc` has `malloc` semantics, not C `realloc` semantics; after a resize the bytes are undefined (a same-bucket resize happens to keep them in place, but do not rely on it). Only call `realloc` with a slice that belongs to this allocator (or a fresh/empty `Slice`); passing a slice from another pool, or freeing the same slice twice, corrupts the allocator's accounting. | ||
| - `realloc(slice: Slice, byteLength: number): Slice` — Resize a slice, or free it by passing `0`. **Contents are not preserved** — `realloc` has `malloc` semantics, not C `realloc` semantics; after a resize the bytes are undefined (a same-bucket resize happens to keep them in place, but do not rely on it). Only call `realloc` with a slice that belongs to this allocator (or a fresh/empty `Slice`); passing a slice from another pool, or freeing the same pool slot through two aliasing `Slice` objects, corrupts the allocator's accounting. (Calling `realloc(slice, 0)` twice on the _same_ object is a harmless no-op — the first free empties the slice, so the second returns immediately.) | ||
| - `isFromPool(slice: Slice | null | undefined): boolean` — Check if a slice's buffer is this pool's backing buffer. Note this is an identity check; it returns `true` for any slice over the same buffer, not only ones this allocator handed out. | ||
@@ -147,0 +153,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
51212
72.8%5
-16.67%7
40%488
1.46%167
3.73%1
Infinity%