package ocsigenserver

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Ocsigen_streamSource

Sourceexception Interrupted of exn
Sourceexception Cancelled
Sourceexception Already_read
Sourceexception Finalized

Streams are a means to read data block by block

Sourcetype 'a stream
Sourcetype 'a step = private
  1. | Finished of 'a stream option
  2. | Cont of 'a * '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.

Sourcetype 'a t
Sourcetype outcome = [
  1. | `Success
  2. | `Failure
]
Sourceval make : ?finalize:(outcome -> unit Lwt.t) -> (unit -> 'a step Lwt.t) -> 'a t

creates a new stream

Sourceval get : 'a t -> 'a stream

call this function if you decide to start reading a stream.

Sourceval next : 'a stream -> 'a step Lwt.t

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.

Sourceval empty : (unit -> 'a step Lwt.t) option -> 'a step Lwt.t

creates an empty step. The parameter is the following substream, if any.

Sourceval cont : 'a -> (unit -> 'a step Lwt.t) -> 'a step Lwt.t

creates a non empty step.

Sourceval add_finalizer : 'a t -> (outcome -> unit Lwt.t) -> unit

Add a finalizer function. In the current version, finalizers must be called manually.

Sourceval finalize : 'a t -> outcome -> unit Lwt.t

Finalize the stream. This function must be called explicitly after reading the stream, otherwise finalizers won't be called.

Sourceval 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

Sourceval consume : 'a t -> unit Lwt.t

Consume without cancelling. Read the stream until the end, without decoding.

Sourceexception Stream_too_small

possibly with the size of the stream

Sourceexception Stream_error of string
Sourceexception String_too_large
Sourceval string_of_stream : int -> string stream -> string Lwt.t

Creates a string from a stream. The first argument is the upper limit of the string length

Sourceval enlarge_stream : string step -> string step Lwt.t

Read more data in the buffer

Sourceval stream_want : string step -> int -> string step Lwt.t

stream_want s len Returns a stream with at least len bytes in the buffer if possible

Sourceval current_buffer : string step -> string

Returns the value of the current buffer

Sourceval skip : string step -> int64 -> string step Lwt.t

Skips data. Raises Stream_too_small (Some size) if the stream is too small, where size is the size of the stream.

Sourceval substream : string -> string step -> string step Lwt.t

Cut the stream at the position given by a string delimiter

Sourceval of_file : string -> string t

returns a stream reading from a file. Do not forget to finalize the stream to close the file.

Sourceval of_string : string -> string t

returns a stream containing a string.

Sourceval of_lwt_stream : 'a Lwt_stream.t -> 'a t

Convert a Lwt_stream.t to an Ocsigen_stream.t.

Sourceval to_lwt_stream : ?is_empty:('a -> bool) -> 'a t -> 'a Lwt_stream.t

Convert an Ocsigen_stream.t into a Lwt_stream.t.

  • parameter is_empty

    function to skip empty chunk.

Sourcemodule StringStream : sig ... end
OCaml

Innovation. Community. Security.