toBuffer

Bun

Symbol

toBuffer

function toBuffer(ptr: Pointer, byteOffset?: number, byteLength?: number): Buffer

Read a pointer as a Buffer

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 }