Module type Runtime.Response_body

type +'a io
type t

Runtime-owned response body value.

type reader

Scoped response-body reader. It must not be used outside with_reader.

val read : reader -> bytes -> off:int -> len:int -> (int, Error.t) Stdlib.result io

Read into bytes. Returns Ok 0 at end-of-body. Invalid bounds return Error Body. Native runtime cancellation remains native. After a read error, timeout, or cancellation, the reader is no longer valid.

val next : ?chunk_size:int -> reader -> (bytes option, Error.t) Stdlib.result io

Read the next chunk, or None at end-of-body. chunk_size must be positive.

val with_reader : t -> consume:(reader -> ('a, Error.t) Stdlib.result io) -> ('a, Error.t) Stdlib.result io

Scope a response body reader to consume.

Callers must not retain the reader after consume returns. Runtime adapters must attempt to drain or discard the response body after consume. If consume returns Ok _, a drain failure is returned. If consume returns Error _, that error wins over cleanup failures. If consume raises or native cancellation occurs, cleanup is attempted and the original exception or cancellation is preserved.

val discard : t -> (unit, Error.t) Stdlib.result io

Drain and ignore the response body, subject to the runtime drain timeout and byte limit.