package decompress

  1. Overview
  2. Docs
Implementation of Zlib and GZip in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

decompress-v1.1.0.tbz
sha256=a950f91c33af4d14b25c62dd3edf7067b4020b7f39c2664a2afa925f767be2b9
sha512=abb4994150ef724b4cbf0612e0215092818139a5eca33c2365b6fdac61e4e33323da490fd8ea1adf8348c136b11a6448b1500173352f7b61f7641d32c02f3874

doc/decompress.zl/Zl/Def/index.html

Module Zl.DefSource

Sourcetype src = [
  1. | `Channel of in_channel
  2. | `String of string
  3. | `Manual
]

The type for input sources. With a `Manual source the client must provide input with src. With `String or `Channel source the client can safely discard `Await case (with assert false).

Sourcetype dst = [
  1. | `Channel of out_channel
  2. | `Buffer of Buffer.t
  3. | `Manual
]

The type for output destinations. With a `Manual destination the client must provide output storage with dst. With `String or `Channel destination the client can safely discard `Flush case (with assert false).

Sourcetype encoder

The type for ZLIB encoders.

Sourcetype ret = [
  1. | `Await of encoder
  2. | `End of encoder
  3. | `Flush of encoder
]
Sourceval encoder : src -> dst -> q:De.Queue.t -> w:window -> level:int -> encoder

encoder src dst ~q ~w ~level is an encoder that inputs from src and that outputs to dst.

Internal queue.

encoder deals internally with compression algorithm and DEFLATE encoder. To pass compression values to DEFLATE encoder, we need a queue q. Length of q has an impact on performance, and small lengths can be a bottleneck, leading encode to emit many `Flush. We recommend a queue as large as output buffer.

Window.

ZLIB is able to constrain length of window used to do LZ77 compression. However, small window can slow-down LZ77 compression algorithm. Small windows are mostly used to enable inflation of output in memory-constrained environments, for example when compressed data from untrusted sources must be processed.

Level.

Current implementation of ZLIB does not handle any compression level. However, the client must give a level between 0 and 3, inclusively. Otherwise, we raise an Invalid_argument.

Sourceval src_rem : encoder -> int

src_rem e is how many bytes it remains in given input buffer.

Sourceval dst_rem : encoder -> int

dst_rem e is how many unused bytes remain in the output buffer of e.

Sourceval src : encoder -> bigstring -> int -> int -> encoder

src e s j l provides e with l bytes to read, starting at j in s. This byte range is read by calls to encode with e until `Await is returned. To signal the end of input call the function with l = 0.

Sourceval dst : encoder -> bigstring -> int -> int -> encoder

dst e s j l provides e with l bytes available to write, starting at j in s. This byte range is fill by calls to encode with e until `Flush is returned.

Sourceval encode : encoder -> ret

encode e0 is:

  • `Await e1 if e0 has a `Manual input source and awaits for more input. The client must use src with e1 to provide it.
  • `Flush e1 if e0 has a `Manual destination and needs more output storage. The client must drain the buffer before resuming operation.
  • `End e1 if e1 encoded all input. Output buffer is possibly not empty (it can be check with dst_rem).
OCaml

Innovation. Community. Security.