Hcs.Stream.Async

hcs · API reference

Asynchronous Stream (Eio)

Streams that integrate with Eio's structured concurrency.

type 'a t = unit -> 'a option

An asynchronous stream that can be pulled from

Producers

val empty : 'a t
val singleton : 'a -> 'a t
val of_list : 'a list -> 'a t
val of_seq : 'a Seq.t -> 'a t
val of_flow : 
  ?buf_size:int ->
  [> Eio.Flow.source_ty ] Eio.Flow.source ->
  Cstruct.t t

Create a stream from an Eio flow (reads until EOF)

val of_file : 
  ?buf_size:int ->
  fs:[> Eio.Fs.dir_ty ] Eio.Fs.dir ->
  Eio.Fs.path ->
  Cstruct.t t

Create a stream that reads a file in chunks

Transformers

val map : ('a -> 'b) -> 'a t -> 'b t
val filter : ('a -> bool) -> 'a t -> 'a t
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
val take : int -> 'a t -> 'a t

Consumers

val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b

Fold over the stream

val iter : ('a -> 'b) -> 'a t -> unit

Iterate over the stream

val drain : 'a t -> unit

Drain the stream

val to_list : 'a t -> 'a list

Collect into a list

val to_flow : [> Eio.Flow.sink_ty ] Eio.Flow.sink -> Cstruct.t t -> unit

Write stream to an Eio flow

Cstruct-specific operations

val cstructs_to_string : Cstruct.t t -> string

Concatenate a stream of Cstructs into a single string

val cstructs_to_cstruct : Cstruct.t t -> Cstruct.t

Read entire stream into a Cstruct