export type Bytes = Uint8Array<ArrayBuffer>
export type Words = Uint32Array<ArrayBuffer>
-/** Constructor bound before anything can replace the global. */
const TypedArray = Object.getPrototypeOf(Uint8Array.prototype)
const bytesSet = Function.prototype.call.bind(Uint8Array.prototype.set)
return getByteLength(bytes)
}
-/** Captured version of `Uint8Array.prototype.byteLength`. */
-export function byteOffset (bytes: Uint8Array): number {
- return getByteOffset(bytes)
-}
-
/** `target.set(source, offset)` through the captured method. */
export function copy (dst: Uint8Array, src: Uint8Array, offset?: number): void {
return bytesSet(dst, src, offset)
export const isLE = new Uint8Array(getBuffer(new Uint32Array([1])))[0] === 1
/**
- * Captured version of `Uint32Array` reusing input offset and length.
* Enables reading multiple bytes in a single load which is more efficient than
* reading and combining individual bytes with bitshifts. The caller is
* responsible for managing endianness.
}
const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt)
-const fromCharCode = String.fromCharCode
/** 0-9a-f for a valid hex digit 0..15 */
function hexcode (c: number): number {
let hex = ''
for (let i = 0; i < byteLength; i++) {
const byte = bytes[i]
- hex += fromCharCode(hexcode(byte >> 4), hexcode(byte & 15))
+ hex += String.fromCharCode(hexcode(byte >> 4), hexcode(byte & 15))
}
return hex
}