package decompress

  1. Overview
  2. Docs

Inflate algorithm.

A functionnal non-blocking implementation of Zlib algorithm.

type error =
  1. | Invalid_kind_of_block
    (*

    This error appears when the kind of the current block is wrong.

    *)
  2. | Invalid_complement_of_length
    (*

    This error appears when we compute a stored block and length do not correspond with the complement of length.

    *)
  3. | Invalid_dictionary
    (*

    This error appears when we compute a dynamic block and we catch an error when we try to decode the dictionary.

    *)
  4. | Invalid_crc
    (*

    The checksum of the output produced does not equal with the checksum of the stream.

    *)

Inflate error.

type ('i, 'o) t

The state of the inflate algorithm. 'i and 'o are the implementation used respectively for the input and the output, see B.st and B.bs. The typer considers than 'i = 'o.

val pp_error : Format.formatter -> error -> unit

Pretty-printer of inflate error.

val pp : Format.formatter -> ('i, 'o) t -> unit

Pretty-printer of inflate state.

val eval : 'a B.t -> 'a B.t -> ('a, 'a) t -> [ `Await of ('a, 'a) t | `Flush of ('a, 'a) t | `End of ('a, 'a) t | `Error of ('a, 'a) t * error ]

eval i o t computes the state t with the input i and the output o. This function returns:

  • `Await t: the state t waits a new input, may be you use refill.
  • `Flush t: the state t completes the output, may be you use flush.
  • `End t: means that the deflate algorithm is done in your input. May be t writes something in your output. You can check with used_out.
  • `Error (t, exn): the algorithm catches an error exn.
val refill : int -> int -> ('i, 'o) t -> ('i, 'o) t

refill off len t allows the state t to use an output at off on len byte(s).

val flush : int -> int -> ('i, 'o) t -> ('i, 'o) t

flush off len t allows the state t to use an output at off on len byte(s).

val used_in : ('i, 'o) t -> int

used_in t returns how many byte(s) was used by t in the input.

val used_out : ('i, 'o) t -> int

used_out ŧ returns how many byte(s) was used by t in the output.

val write : ('i, 'o) t -> int

write t returns the size of the stream decompressed.

val default : 'o Window.t -> ('i, 'o) t

default makes a new state t.

val to_result : 'a B.t -> 'a B.t -> ('a B.t -> int) -> ('a B.t -> int -> int) -> ('a, 'a) t -> (('a, 'a) t, error) result

to_result i o refill flush t is a convenience function to apply the inflate algorithm on the stream refill and call flush when the internal output is full (and need to flush).

If the compute catch an error, we returns Error exn (see INFLATE.error). Otherwise, we returns the state useless t.

val bytes : Bytes.t -> Bytes.t -> (Bytes.t -> int) -> (Bytes.t -> int -> int) -> (B.st, B.st) t -> ((B.st, B.st) t, error) result

Specialization of to_result with B.Bytes.t.

val bigstring : B.Bigstring.t -> B.Bigstring.t -> (B.Bigstring.t -> int) -> (B.Bigstring.t -> int -> int) -> (B.bs, B.bs) t -> ((B.bs, B.bs) t, error) result

Specialization of to_result with B.Bigstring.t.

OCaml

Innovation. Community. Security.