baml.io.Read

A common interface for reading bytes from a source.

Reference version

Signature

interface baml.io.Read

A common interface for reading bytes from a source.

Implementors are expected to provide a read method that attempts to read up to limit bytes from the source.

Based on Rust's Read trait and JavaScript's ReadableStream.

Source:<builtin>/baml/ns_io/read.bamlbytes 371–1594

Required instance methods

function

read

(self, limit: int) -> uint8array | null throws baml.errors.Io

Read up to limit bytes from the source.

Returns null after EOF. A non-null result is empty only when limit is non-positive: null is reserved for end of input, so a caller that asks for no bytes gets an empty read back rather than an EOF signal. Every implementor agrees on this — driving a loop off read therefore requires a positive limit, as bytes and text below use.

Default instance methods

function

bytes

(self) -> uint8array throws baml.errors.Io

Consume all remaining bytes through EOF.