package decompress

  1. Overview
  2. Docs

Deflate algorithm.

A functionnal non-blocking implementation of Zlib algorithm.

type error =
  1. | Lz77_error of L.error
    (*

    This error appears when the Lz77 algorithm produces an error, see L.error.

    *)

Deflate error.

module F : sig ... end

Frequencies module.

type ('i, 'o) t

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

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

Pretty-printer of deflate error.

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

Pretty-printer of deflate state.

val get_frequencies : ('i, 'o) t -> F.t

get_frequencies t returns the current frequencies of the deflate state. See F.t.

val set_frequencies : ?paranoid:bool -> F.t -> ('i, 'o) t -> ('i, 'o) t

set_frequencies f t replaces the frequencies of the state t by f. The paranoid mode (if paranoid = true) checks if the frequencies can be used with the internal Hunk.t list. That means, for all characters and patterns (see Hunk.t), the binding frequencie must be > 0 (however, this check takes a long time).

eg. if we have a Literal 'a', (fst f).(Char.code 'a') > 0.

val finish : ('i, 'o) t -> ('i, 'o) t

finish t means all input was sended. t will produce a new zlib block with the final flag and write the checksum of the input stream.

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

no_flush off len t means to continue the compression of an input at off on len byte(s).

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

partial_flush off len t finishes the current block, then the encoder writes a fixed empty block. So, the output is not aligned. We keep the current frequencies to compute the new Huffman tree for the new next block.

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

sync_flush off len t finishes the current block, then the encoder writes a stored empty block and the output is aligned. We keep the current frequencies to compute the new Huffman tree for the new next block.

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

full_flush off len t finishes the current block, then the encoder writes a stored empty block and the output is aligned. We delete the current frequencies to compute a new frequencies from your input and write a new Huffman tree for the new next block.

type meth =
  1. | PARTIAL
  2. | SYNC
  3. | FULL
val flush_of_meth : meth -> int -> int -> ('i, 'o) t -> ('i, 'o) t

flush_of_meth meth returns the function depending to the method. Like, flush_of_meth SYNC returns sync_flush. It's a convenience function, nothing else.

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 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 ouput o. This function returns:

  • `Await t: the state t waits a new input
  • `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 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 t returns how many byte(s) was used by t in the output.

val default : proof:'o B.t -> ?wbits:int -> int -> ('i, 'o) t

default ~proof ?wbits level makes a new state t. ~proof is an 'a B.t specialized with an implementation (see B.st or B.bs) to informs the state wich implementation you use.

?wbits (by default, wbits = 15) it's the size of the window used by the Lz77 algorithm (see L.default).

?meth can be specified to flush the internal buffer of the compression and create a new zlib block at n bytes specified.

level is level compression:

  • 0: a stored compression (no compression)
  • 1 .. 3: a fixed compression (compression with a static huffman tree)
  • 4 .. 9: a dynamic compression (compression with a canonic huffman tree produced by the input)
val to_result : 'a B.t -> 'a B.t -> ?meth:(meth * int) -> ('a B.t -> int option -> 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 deflate 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 DEFLATE.error). Otherwise, we returns the useless state t.

val bytes : Bytes.t -> Bytes.t -> ?meth:(meth * int) -> (Bytes.t -> int option -> 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 -> ?meth:(meth * int) -> (B.Bigstring.t -> int option -> 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.