module Zlib:sig
..end
This library uses bigarrays as buffers and can therefore release the OCaml
runtime during (de)compression, allowing other OCaml threads to continue.
Author(s): Christopher Zimmermann
See also
type
status =
| |
Ok |
(* |
0
| *) |
| |
Stream_end |
(* |
1
| *) |
| |
Need_dict |
(* |
2
| *) |
| |
Buf_error |
(* |
3 (zlib -5)
| *) |
| |
Data_error |
(* |
4 (zlib -3)
| *) |
Failure _
,
Invalid_argument _
or Out_of_memory
.type
algo =
| |
Deflated |
(* |
Compression algorithm. Only deflate is provided by current zlib.
| *) |
type
strategy =
| |
Default_strategy |
(* |
0
| *) |
| |
Filtered |
(* |
1
| *) |
| |
Huffman_only |
(* |
2
| *) |
| |
RLE |
(* |
3
| *) |
| |
Fixed |
(* |
4
| *) |
type
flush =
| |
No_flush |
(* |
0
| *) |
| |
Partial_flush |
(* |
1
| *) |
| |
Sync_flush |
(* |
2
| *) |
| |
Full_flush |
(* |
3
| *) |
| |
Finish |
(* |
4
| *) |
| |
Block |
(* |
5
| *) |
| |
Trees |
(* |
6
| *) |
Finish
when all input has been provided, otherwise use No_flush
.
For the other flush values see the zlib manual.type
data_type =
| |
Binary |
(* |
0
| *) |
| |
Text |
(* |
1
| *) |
| |
Unknown |
(* |
2
| *) |
type
deflate
type
inflate
type 'a
state
type 'a
t = {
|
state : |
|||
|
mutable in_ba : |
(* |
bigarray input buffer
| *) |
|
mutable out_ba : |
(* |
bigarray output buffer
| *) |
|
mutable in_ofs : |
(* |
offset into the input buffer
| *) |
|
mutable out_ofs : |
(* |
offset into the output buffer
| *) |
|
mutable in_len : |
(* |
Length of available input data
| *) |
|
mutable out_len : |
(* |
Length of available output data
| *) |
|
mutable in_total : |
(* |
Length of input data processed so far
| *) |
|
mutable out_total : |
(* |
Length of output data processed so far
| *) |
|
mutable data_type : |
(* |
For deflate streams a guess about the type of data is returned here:
0
for binary data, 1 for text and 2 for unknown.
For inflate streams the number of unused bits in the last byte taken
from the input stream is stored here.
If | *) |
|
mutable cksum : |
(* |
The checksum of the decompressed data produced resp. consumed so far.
When
Zlib.flate returns Zlib.status.Need_dict the adler32 checksum of the required
dictionary is returned here instead. | *) |
type
header = {
|
text : |
(* |
Compressed data believed to be text?
| *) |
|
mtime : |
(* |
mtime of compressed file. Set to zero if unknown.
| *) |
|
os : |
(* |
filesystem type on which the compressed file was stored.
See RFC1952 for possible values.
| *) |
|
xflags : |
(* |
Extra flags according to RFC1952 . For deflate compression method the
compression level is stored here.
| *) |
|
extra : |
(* |
Extra header field according to RFC1952 .
| *) |
|
name : |
(* |
Original file name of the compressed file translated to ISO 8859-1
(LATIN-1).
| *) |
|
comment : |
(* |
File comment. According to RFC1952 only ISO 8859-1 (LATIN-1) characters
are allowed. Linebreak is a single linefeed.
| *) |
val create_inflate : ?window_bits:int -> unit -> inflate t
create_inflate ()
Creates zlib internal state and buffer description for
decompression.window_bits
: the base 2 logarithm of the maximum window size. It
should be in tha range 8..15 and greater or equal to
the window_bits
parameter used for compression.
By default the zlib format is decoded.
Use a negative value -8..-15 for raw deflate
decompression without zlib or gzip header.
Add 16
to window_bits
to decode the gzip format.
Add 32
to window_bits
to decode zlib or gzip format
with automatic header detection.val create_deflate : ?level:int ->
?algo:algo ->
?window_bits:int ->
?memory:int -> ?strategy:strategy -> unit -> deflate t
level
: the compression level must be betweed -1
and 9
.
-1
selects default compression level, 1
gives best
speed 9
gives best compression, anything in between
is a compromise of speed/compression. 0
gives no
compression at all.algo
: Only Zlib.algo.Deflated
available at the moment.window_bits
: the base 2 logarithm of the maximum window size. It
should be in tha range 8..15 and greater or equal to
the window_bits
parameter used for compression.
Use a negative value -8..-15 for raw deflate
compression without zlib or gzip header.
Add 16 to window_bits
to write a gzip header.memory
: selects how much memory to use for compression in the
range 1..9. More memory means faster and better
compression.
A value of 9
uses 256kb, 8
128kb, 7
64kb...strategy
: See the zlib manual for details about this parameter.val inflate_init : window_bits:int -> inflate state
val deflate_init : level:int ->
algo:algo ->
window_bits:int ->
memory:int -> strategy:strategy -> deflate state
deflate_init level algo window_bits memory strategy
like Zlib.create_deflate
, but
only creates the internal Zlib.state
.val deflate_bound : deflate state -> int -> int
deflate_bound state len
calculates an upper bound on the size of the
compressed data. This functions assumes the zlib format
is used. The resulting compressed size might be larger
than the returned bound when the gzip format is being
used.val flate : 'a t -> flush -> status
flate buffers flush
(de)compresses data from the provided input to the
output buffers.Zlib.status.Ok
if some progress has been made but more input or
output is expected. Zlib.status.Stream_end
if all data has been
processed. Zlib.status.Need_dict
if a dictionary is needed when
inflating zlib data. Zlib.status.Data_error
if the provided data
is inconsistent.val inflate_set_dictionary : inflate state -> string -> status
inflate_set_dictionary state dict
Sets a preset dictionary for
decompression. Must be called after Zlib.flate
requested a
dictionary by returning Zlib.status.Need_dict
; the cksum field of
Zlib.state
will then contain the adler32 checksum of the
required dictionary.Zlib.status.Data_error
when the adler32 checksum of the provided
dictionary doesn't match the requested checksum.val deflate_set_dictionary : deflate state -> string -> int32
deflate_set_dictionary state dict
Sets a preset dictionary for
compression. When using the zlib format this needs to
be called before the first call to Zlib.flate
.
No dictionary may be used for the gzip format.val get_header : inflate state -> header
get_header header
Retrieve a header after a gzip header has been read by
Zlib.flate
.Failure
"Zlib.get_header: Header not yet completed."
if the header has not yet been completely read.Not_found
if not reading gzip format.Zlib.flate
.val set_header : deflate state -> header -> unit
set_header state header
Provide a header when writing the gzip format. Must be
called before any call to Zlib.flate
.val reset : 'a t -> unit
reset buffers
Prepares for a new stream of data to be (de)compressed.
The parameters passed to Zlib.inflate_init
resp.
Zlib.deflate_init
are left unchanged.val get_data_type : deflate t -> data_type
get_data_type buffers
gets the data type of the data being compressed.val adler32 : int32 -> string -> int32
adler32 cksum buf
Updates the running adler32 checksumval adler32_empty : int32
Zlib.adler32