type src = [
`Channel of in_channel
`String of string
The type for input sources. With a
`Manual source the client must provide input with
`Channel source the client can safely discard
`Await case (with
The type for output destinations. With a
`Manual destination the client must provide output storage with
`Channel destination the client can safely discard
`Flush case (with
val encoder : ?dynamic:bool -> q:De.Queue.t -> w:De.Lz77.window -> level:int -> src -> dst -> encoder
encoder ~q ~w ~level src dst is an encoder that inputs from
src and that outputs to
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.
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.
Zlib implements 10 levels (from 0 to 9). All of them use the dynamic & canonic huffman if
true (default). Otherwise, we use the static huffman. The higher the level, the better the ratio.
val src_rem : encoder -> int
src_rem e is how many bytes it remains in given input buffer.
val dst_rem : encoder -> int
dst_rem e is how many unused bytes remain in the output buffer of
src e s j l provides
l bytes to read, starting at
s. This byte range is read by calls to
`Await is returned. To signal the end of input call the function with
l = 0.
dst e s j l provides
l bytes available to write, starting at
s. This byte range is fill by calls to
`Flush is returned.
encode e0 is:
`Manualinput source and awaits for more input. The client must use
e1to provide it.
`Manualdestination and needs more output storage. The client must drain the buffer before resuming operation.
e1encoded all input. Output buffer is possibly not empty (it can be check with
The encoder must manipulate an output buffer of, at least, 2 bytes. If it's not the case,
encode does nothing - and it tells you nothing more than it did nothing. Depending on what you do, a loop can infinitely call
encode without any updates until the given output still has less than 2 bytes.
module Ns : sig ... end