Module Make.Reader

Response-body readers for object consume callbacks.

type 'a io = 'a io

Scoped response body reader.

Readers passed to object consume callbacks are valid only until the callback returns. Drain, copy, or decode the body inside that callback.

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

Read up to len bytes into bytes starting at off.

Returns Ok 0 at end of body.

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

Read the next fresh chunk, or None at end of body.

chunk_size must be positive when supplied.

val fold : ?chunk_size:int -> t -> init:'a -> f:('a -> bytes -> ('a, Awskit.Error.t) Stdlib.result io) -> ('a, Awskit.Error.t) Stdlib.result io

Fold over response-body chunks until end of body or the callback returns an error.

val iter : ?chunk_size:int -> t -> f:(bytes -> (unit, Awskit.Error.t) Stdlib.result io) -> (unit, Awskit.Error.t) Stdlib.result io

Iterate over response-body chunks until end of body or the callback returns an error.

val to_bytes : ?chunk_size:int -> max_bytes:int64 -> t -> (bytes, Awskit.Error.t) Stdlib.result io

Drain the body into memory as bytes, failing if it exceeds max_bytes.

val to_string : ?chunk_size:int -> max_bytes:int64 -> t -> (string, Awskit.Error.t) Stdlib.result io

Drain the body into a string, failing if it exceeds max_bytes.