Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils/buffer

Index

Type aliases

BinaryLike

BinaryLike: string | number | bigint | ArrayBufferLike | number[]

Functions

Const addPadding

  • addPadding(buffer: Uint8Array, length?: number): Uint8Array
  • Add padding to a buffer. If the buffer is larger than length, this function won't do anything. If it's smaller, the buffer will be padded to the specified length, with extra zeroes at the end.

    Parameters

    • buffer: Uint8Array

      The buffer to add padding to.

    • length: number = ...

    Returns Uint8Array

    The padded buffer.

Const concat

  • concat(buffers: Uint8Array[]): Uint8Array
  • Safe function to merge multiple Uint8Arrays into a single Uint8array. This works with buffers of any size.

    Parameters

    • buffers: Uint8Array[]

      The buffers to combine.

    Returns Uint8Array

    The combined buffers.

Const fromHex

  • fromHex(data: string): Uint8Array
  • Get a hexadecimal string as Uint8Array.

    Parameters

    • data: string

      The hexadecimal string to convert to a buffer.

    Returns Uint8Array

    The buffer.

Const fromUtf8

  • fromUtf8(data: string): Uint8Array
  • Get a UTF-8 encoded string as buffer.

    Parameters

    • data: string

      The string to convert to a buffer.

    Returns Uint8Array

    The buffer.

Const getTextDecoder

  • getTextDecoder(encoding?: string): TextDecoder
  • Returns an instance of TextDecoder that works with both Node.js and web browsers.

    Parameters

    • encoding: string = 'utf8'

    Returns TextDecoder

Const getTextEncoder

  • getTextEncoder(): TextEncoder
  • Returns an instance of TextEncoder that works with both Node.js and web browsers.

    Returns TextEncoder

Const stripPrefix

  • stripPrefix(value: string): string

Const toBuffer

  • Attempt to parse a value as Uint8Array. If data is a number, this will pad the buffer to 32 bytes.

    Parameters

    • data: BinaryLike

      The value to parse as Uint8Array.

    Returns Uint8Array

    The resulting Uint8Array.

Const toHex

  • toHex(data: Uint8Array): string
  • Get a Uint8Array as hexadecimal string.

    Parameters

    • data: Uint8Array

      The buffer to convert to a hexadecimal string.

    Returns string

    The buffer as hexadecimal string.

Const toNumber

  • toNumber(buffer: Uint8Array): bigint
  • Get a number from a buffer. Returns zero if the buffer is empty.

    Parameters

    • buffer: Uint8Array

      The buffer to get a number for.

    Returns bigint

    The parsed number.

Const toUtf8

  • toUtf8(data: Uint8Array): string
  • Get a buffer as UTF-8 encoded string.

    Parameters

    • data: Uint8Array

      The buffer to convert to UTF-8.

    Returns string

    The buffer as UTF-8 encoded string.

Generated using TypeDoc