function

ffi.toBuffer

function toBuffer(
ptr: number | bigint | 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.

Bun catches some invalid pointers, but not all. Passing an invalid pointer, or reading past the end of the memory it points to, can crash the program or cause undefined behavior.

@param ptr

The memory address to read

@param byteOffset

bytes to skip before reading

@param byteLength

bytes to read

Referenced types

type Pointer = number & { __pointer__: null }