toArrayBuffer

Bun

Symbol

toArrayBuffer

function toArrayBuffer(ptr: Pointer, byteOffset?: number, byteLength?: number): ArrayBuffer

Read a pointer as an ArrayBuffer

If byteLength is not provided, the pointer is assumed to be 0-terminated.

@param ptr

The memory address to read

@param byteOffset

bytes to skip before reading

@param byteLength

bytes to read

While there are some checks to catch invalid pointers, this is a difficult thing to do safely. Passing an invalid pointer can crash the program and reading beyond the bounds of the pointer will crash the program or cause undefined behavior. Use with care!

Referenced types

type Pointer = number & { __pointer__: null }

class ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.

  • readonly [Symbol.toStringTag]: string
  • readonly byteLength: number

    Read-only. The length of the ArrayBuffer (in bytes).

  • resize(newByteLength?: number): void

    Resizes the ArrayBuffer to the specified size (in bytes).

    MDN

    resize(byteLength: number): ArrayBuffer

    Resize an ArrayBuffer in-place.

  • slice(begin: number, end?: number): ArrayBuffer

    Returns a section of an ArrayBuffer.

  • transfer(newByteLength?: number): ArrayBuffer

    Creates a new ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN

  • transferToFixedLength(newByteLength?: number): ArrayBuffer

    Creates a new non-resizable ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN