package decompress

  1. Overview
  2. Docs
include DEFLATE with type error = error_rfc1951_deflate

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 Buffer.bytes and Buffer.bigstring. The typer considers than 'i = 'o.

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

Pretty-printer of deflate error.

val pp : Stdlib.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 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 : ('x, 'x) t -> ('x, 'x) 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 -> ('x, 'x) t -> ('x, 'x) 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 -> ('x, 'x) t -> ('x, 'x) 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 -> ('x, 'x) t -> ('x, 'x) 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 -> ('x, 'x) t -> ('x, 'x) 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 -> ('x, 'x) t -> ('x, 'x) 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 -> 'a -> ('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 : witness:'a Buffer.t -> ?wbits:int -> int -> ('a, 'a) t

default ~witness ?wbits level makes a new state t. ~witness is an 'a Buffer.t specialized with an implementation (see Buffer.bytes or Buffer.bigstring) 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 Lz77.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 -> 'a -> ?meth:(meth * int) -> ('a -> int option -> int) -> ('a -> int -> int) -> ('a, 'a) t -> (('a, 'a) t, error) Stdlib.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 : Stdlib.Bytes.t -> Stdlib.Bytes.t -> ?meth:(meth * int) -> (Stdlib.Bytes.t -> int option -> int) -> (Stdlib.Bytes.t -> int -> int) -> (Stdlib.Bytes.t, Stdlib.Bytes.t) t -> ((Stdlib.Bytes.t, Stdlib.Bytes.t) t, error) Stdlib.result

Specialization of to_result with Buffer.Bytes.t.

val bigstring : Buffer.Bigstring.t -> Buffer.Bigstring.t -> ?meth:(meth * int) -> (Buffer.Bigstring.t -> int option -> int) -> (Buffer.Bigstring.t -> int -> int) -> (Buffer.Bigstring.t, Buffer.Bigstring.t) t -> ((Buffer.Bigstring.t, Buffer.Bigstring.t) t, error) Stdlib.result

Specialization of to_result with Buffer.Bigstring.t.

val bits_remaining : ('x, 'x) t -> int
OCaml

Innovation. Community. Security.