namespace

ffi.read

namespace read

Read a value directly from a memory address, without creating a DataView or ArrayBuffer

  • function f32(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a 32-bit float at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function f64(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a 64-bit double at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function i16(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a signed 16-bit integer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function i32(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a signed 32-bit integer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function i64(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): bigint;

    Read a signed 64-bit integer at ptr + byteOffset, as a bigint

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function i8(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a signed 8-bit integer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function intptr(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a pointer-sized signed integer (intptr_t) at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function ptr(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read a pointer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function u16(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read an unsigned 16-bit integer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function u32(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read an unsigned 32-bit integer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function u64(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): bigint;

    Read an unsigned 64-bit integer at ptr + byteOffset, as a bigint

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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

  • function u8(
    ptr: number | bigint | Pointer,
    byteOffset?: number
    ): number;

    Read an unsigned 8-bit integer at ptr + byteOffset

    Behaves like DataView, but is usually faster because it doesn't create a DataView or ArrayBuffer.

    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