Type Alias ByteUtilsExperimental

ByteUtils: {
    allocate: ((size: number) => Uint8Array);
    allocateUnsafe: ((size: number) => Uint8Array);
    compare: ((buffer1: Uint8Array, buffer2: Uint8Array) => -1 | 0 | 1);
    concat: ((list: Uint8Array[]) => Uint8Array);
    encodeUTF8Into: ((destination: Uint8Array, source: string, byteOffset: number) => number);
    equals: ((a: Uint8Array, b: Uint8Array) => boolean);
    fromBase64: ((base64: string) => Uint8Array);
    fromHex: ((hex: string) => Uint8Array);
    fromISO88591: ((codePoints: string) => Uint8Array);
    fromNumberArray: ((array: number[]) => Uint8Array);
    fromUTF8: ((utf8: string) => Uint8Array);
    isUint8Array: ((value: unknown) => value is Uint8Array);
    randomBytes: ((byteLength: number) => Uint8Array);
    swap32: ((buffer: Uint8Array) => Uint8Array);
    toBase64: ((buffer: Uint8Array) => string);
    toHex: ((buffer: Uint8Array) => string);
    toISO88591: ((buffer: Uint8Array) => string);
    toLocalBufferType: ((buffer: Uint8Array | ArrayBufferView | ArrayBuffer) => Uint8Array);
    toUTF8: ((buffer: Uint8Array, start: number, end: number, fatal: boolean) => string);
    utf8ByteLength: ((input: string) => number);
}

A collection of functions that help work with data in a Uint8Array. ByteUtils is configured at load time to use Node.js or Web based APIs for the internal implementations.

Type declaration

  • allocate: ((size: number) => Uint8Array)

    Create empty space of size

      • (size): Uint8Array
      • Parameters

        • size: number

        Returns Uint8Array

  • allocateUnsafe: ((size: number) => Uint8Array)

    Create empty space of size, use pooled memory when available

      • (size): Uint8Array
      • Parameters

        • size: number

        Returns Uint8Array

  • compare: ((buffer1: Uint8Array, buffer2: Uint8Array) => -1 | 0 | 1)

    Compare 2 Uint8Arrays lexicographically

      • (buffer1, buffer2): -1 | 0 | 1
      • Parameters

        • buffer1: Uint8Array
        • buffer2: Uint8Array

        Returns -1 | 0 | 1

  • concat: ((list: Uint8Array[]) => Uint8Array)

    Concatenating all the Uint8Arrays in new Uint8Array.

      • (list): Uint8Array
      • Parameters

        • list: Uint8Array[]

        Returns Uint8Array

  • encodeUTF8Into: ((destination: Uint8Array, source: string, byteOffset: number) => number)

    Encode UTF8 bytes generated from source string into destination at byteOffset. Returns the number of bytes encoded.

      • (destination, source, byteOffset): number
      • Parameters

        • destination: Uint8Array
        • source: string
        • byteOffset: number

        Returns number

  • equals: ((a: Uint8Array, b: Uint8Array) => boolean)

    Check if two Uint8Arrays are deep equal

      • (a, b): boolean
      • Parameters

        • a: Uint8Array
        • b: Uint8Array

        Returns boolean

  • fromBase64: ((base64: string) => Uint8Array)

    Create a Uint8Array from a base64 string

      • (base64): Uint8Array
      • Parameters

        • base64: string

        Returns Uint8Array

  • fromHex: ((hex: string) => Uint8Array)

    Create a Uint8Array from a hex string

      • (hex): Uint8Array
      • Parameters

        • hex: string

        Returns Uint8Array

  • fromISO88591: ((codePoints: string) => Uint8Array)

    Legacy binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format

      • (codePoints): Uint8Array
      • Parameters

        • codePoints: string

        Returns Uint8Array

  • fromNumberArray: ((array: number[]) => Uint8Array)

    Create a Uint8Array from an array of numbers

      • (array): Uint8Array
      • Parameters

        • array: number[]

        Returns Uint8Array

  • fromUTF8: ((utf8: string) => Uint8Array)

    Create a Uint8Array from a UTF8 string

      • (utf8): Uint8Array
      • Parameters

        • utf8: string

        Returns Uint8Array

  • isUint8Array: ((value: unknown) => value is Uint8Array)

    Checks if the given value is a Uint8Array.

      • (value): value is Uint8Array
      • Parameters

        • value: unknown

        Returns value is Uint8Array

  • randomBytes: ((byteLength: number) => Uint8Array)

    Generate a Uint8Array filled with random bytes with byteLength

      • (byteLength): Uint8Array
      • Parameters

        • byteLength: number

        Returns Uint8Array

  • swap32: ((buffer: Uint8Array) => Uint8Array)

    Interprets buffer as an array of 32-bit values and swaps the byte order in-place.

      • (buffer): Uint8Array
      • Parameters

        • buffer: Uint8Array

        Returns Uint8Array

  • toBase64: ((buffer: Uint8Array) => string)

    Create a base64 string from bytes

      • (buffer): string
      • Parameters

        • buffer: Uint8Array

        Returns string

  • toHex: ((buffer: Uint8Array) => string)

    Create a lowercase hex string from bytes

      • (buffer): string
      • Parameters

        • buffer: Uint8Array

        Returns string

  • toISO88591: ((buffer: Uint8Array) => string)

    Legacy binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format

      • (buffer): string
      • Parameters

        • buffer: Uint8Array

        Returns string

  • toLocalBufferType: ((buffer: Uint8Array | ArrayBufferView | ArrayBuffer) => Uint8Array)

    Transforms the input to an instance of Buffer if running on node, otherwise Uint8Array

      • (buffer): Uint8Array
      • Parameters

        • buffer: Uint8Array | ArrayBufferView | ArrayBuffer

        Returns Uint8Array

  • toUTF8: ((buffer: Uint8Array, start: number, end: number, fatal: boolean) => string)

    Create a string from utf8 code units, fatal=true will throw an error if UTF-8 bytes are invalid, fatal=false will insert replacement characters

      • (buffer, start, end, fatal): string
      • Parameters

        • buffer: Uint8Array
        • start: number
        • end: number
        • fatal: boolean

        Returns string

  • utf8ByteLength: ((input: string) => number)

    Get the utf8 code unit count from a string if it were to be transformed to utf8

      • (input): number
      • Parameters

        • input: string

        Returns number