Library
Module
Module type
Parameter
Class
Class type
Bindings to the zlib compression library providing deflate compression with or without zlib or gzip headers.
This library uses bigarrays as buffers and can therefore release the OCaml runtime during (de)compression, allowing other OCaml threads to continue.
Zlib return codes. Only non-fatal return codes are returned. Fatal error codes are translated to the standard exceptions Failure _
, Invalid_argument _
or Out_of_memory
.
Compression strategy - see zlib manual for details.
The type of the flush parameter passed to flate. Use Finish
when all input has been provided, otherwise use No_flush
. For the other flush values see the zlib manual.
Best guess of flate about the type of data being compressed.
type 'a t = {
state : 'a state;
mutable in_buf : bigstring;
bigstring input buffer
*)mutable out_buf : bigstring;
bigstring output buffer
*)mutable in_ofs : int;
offset into the input buffer
*)mutable out_ofs : int;
offset into the output buffer
*)mutable in_len : int;
Length of available input data
*)mutable out_len : int;
Length of available output data
*)mutable in_total : int;
Length of input data processed so far
*)mutable out_total : int;
Length of output data processed so far
*)mutable data_type : int;
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 flate
just finished decoding the header or returned after an end-of-block code 128
is added. If flate
is currentry decoding the last block 64
is added.
mutable cksum : int32;
The checksum of the decompressed data produced resp. consumed so far. When flate
returns status.Need_dict
the adler32 checksum of the required dictionary is returned here instead.
}
Record holding the internal state and input / output buffers of data as well as other data returned from the zlib inflate and deflate routines.
type header = {
text : bool;
Compressed data believed to be text?
*)mtime : int32;
mtime of compressed file. Set to zero if unknown.
*)os : int;
xflags : int;
Extra flags according to RFC1952. For deflate compression method the compression level is stored here.
*)extra : string option;
name : string option;
Original file name of the compressed file translated to ISO 8859-1 (LATIN-1).
*)comment : string option;
File comment. According to RFC1952 only ISO 8859-1 (LATIN-1) characters are allowed. Linebreak is a single linefeed.
*)}
Record holding the data in a gzip header.
create_inflate ()
Creates zlib internal state and buffer description for decompression.
val create_deflate :
?level:int ->
?algo:algo ->
?window_bits:int ->
?memory:int ->
?strategy:strategy ->
unit ->
deflate t
create_deflate ()
Creates zlib internal state
and buffer description for compression.
inflate_init window_bits
like create_inflate
, but only creates the internal 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 create_deflate
, but only creates the internal state
.
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.
flate buffers flush
(de)compresses data from the provided input to the output buffers.
inflate_set_dictionary state dict
Sets a preset dictionary for decompression. Must be called after flate
requested a dictionary by returning status.Need_dict
; the cksum field of state
will then contain the adler32 checksum of the required dictionary.
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 flate
. No dictionary may be used for the gzip format.
get_header header
Retrieve a header after a gzip header has been read by flate
.
set_header state header
Provide a header when writing the gzip format. Must be called before any call to flate
.
val reset : 'a t -> unit
reset buffers
Prepares for a new stream of data to be (de)compressed. The parameters passed to inflate_init
resp. deflate_init
are left unchanged.
get_data_type buffers
gets the data type of the data being compressed.
Initial value to be used with adler32