Module Ocsigen_stream
module Ocsigen_stream: sig..end
Streams are a means to read data block by block
exception Interrupted of exn
exception Cancelled
exception Already_read
exception Finalized
Streams are a means to read data block by block
type 'a stream
A stream may be composed by several substreams.
Thus a stream is either something that contains the current buffer and
a function to retrieve the following data,
or a finished stream with possibly another stream following.
type 'a t
creates a new stream
call this function if you decide to start reading a stream.
Raises Already_read if the stream has already been read.
get the next step of a stream.
Fails with Interrupted e if reading the thread failed with exception e,
and with Cancelled if the thread has been cancelled.
creates an empty step. The parameter is the following substream, if any.
creates a non empty step.
val add_finalizer : 'a t -> (unit -> unit Lwt.t) -> unit
Add a finalizer function
val finalize : 'a t -> unit Lwt.t
Finalize the stream
val cancel : 'a t -> unit Lwt.t
Cancel the stream, i.e. read the stream until the end, without decoding.
Further tries to read on the stream will fail with exception
Ocsigen_stream.Cancelled
val consume : 'a t -> unit Lwt.t
Consume without cancelling.
Read the stream until the end, without decoding.
exception Stream_too_small
possibly with the size of the stream
exception Stream_error of string
exception String_too_large
val string_of_stream : string stream -> string Lwt.t
Creates a string from a stream
Read more data in the buffer
stream_want s len Returns a stream with at least len
bytes in the buffer if possible
val current_buffer : string step -> string
Returns the value of the current buffer
Skips data. Raises Stream_too_small (Some size)
if the stream is too small, where size is the size of the stream.
Cut the stream at the position given by a string delimiter
val of_file : string -> string t
returns a stream reading from a file.
Do not forget to finalize the stream to close the file.
val of_string : string -> string t
returns a stream containing a string.