baml.io.Write

A common interface for writing bytes to a destination.

Reference version

Signature

interface baml.io.Write

A common interface for writing bytes to a destination.

Callers can also write UTF-8-encoded strings via the write method.

Implementors are expected to provide a write_some method that attempts to write up to limit bytes to the destination.

Based on Rust's Write trait and JavaScript's WritableStream.

Source:<builtin>/baml/ns_io/write.bamlbytes 463–1874

Required instance methods

function

write_some

(self, data: uint8array) -> int throws baml.errors.Io

Attempt one write of data and return the number of bytes accepted. A partial write is successful.

function

flush

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

Push data buffered by this writer toward its destination.

Default instance methods

function

write

(self, data: string | uint8array) -> int throws baml.errors.Io

Write all of data to the destination. Strings are encoded as UTF-8. Returns the number of bytes written.

Like Rust's write_all, this does not flush: it is a loop over write_some, and pushing buffered bytes onward stays the caller's separate flush. Implementors are expected to make write_some report its own failures rather than defer them.