gossamer/array_buffer

A transit type for JavaScript ArrayBuffer interop. For byte data in pure Gleam, prefer BitArray; bridge with from_bit_array / to_bit_array.

Types

A generic raw binary data buffer.

ArrayBuffer is a transit type — it exists for interop with JavaScript APIs that specifically require an ArrayBuffer. For byte data in Gleam, prefer BitArray. Bridge with from_bit_array / to_bit_array.

See ArrayBuffer on MDN.

pub type ArrayBuffer

Values

pub fn byte_length(array_buffer: ArrayBuffer) -> Int

The size of the buffer in bytes.

pub fn from_bit_array(bit_array: BitArray) -> ArrayBuffer

Creates an ArrayBuffer containing the bytes of bit_array. Un-aligned bit arrays are zero-padded to the next byte.

pub fn new(byte_length: Int) -> ArrayBuffer

Creates a fixed-size ArrayBuffer of byte_length bytes. A non-positive byte_length returns an empty buffer. Panics when byte_length exceeds the engine’s maximum buffer size.

pub fn to_bit_array(array_buffer: ArrayBuffer) -> BitArray

Wraps the buffer’s bytes as a BitArray.

Search Document