Module Bytes.Stream

Byte streams.

Byte streams have no concrete incarnation. They are observed by Bytes.Readers and Bytes.Writers.


type pos = int

The type for stream positions.

The position of a stream is the zero-based byte index of the next byte to read or write. It can also be seen as the count of bytes read or written by a stream reader or writer.


type format = string

The type for stream formats. An identifier for the format of read or written bytes. Favour lowercased file extensions without the dot or mime types.


type error = ..

The type for stream errors. Stream formats add their own cases to this type.

type error_context

The type for error contexts.

exception Error of error * error_context

The exception raised by streams reader, writers and their creation functions.

val error_message : (error * error_context) -> string

error_message e turns error e into an error message for humans.

val error_to_result : (error * error_context) -> ('a, string) Stdlib.result

error_to_result e is Result.Error (error_message e).

type 'e format_error

The type for describing errors of type 'e for a stream format.

val make_format_error : format:format -> case:('e -> error) -> message:(error -> string) -> 'e format_error

make_format_error ~format ~case ~message describes the type of error for format format:

  • format identifies the stream format.
  • case is the function that injects the type into error.
  • message is a function that must stringify the results of case.
val error : 'e format_error -> ?context:[ `R | `W ] -> 'e -> 'a

error fmt e errors with e for a stream fmt by raising an Error exception.


type error +=
  1. | Limit of int

    The inclusive byte count limit.


The type for stream limits errors.

val limit_error : int format_error

limit_error is a stream limit error.