module Bz2:sig..end
The module Bz provides a basic interface to the bzip2
compression library.
type in_channel
type out_channel
exception IO_error of string
Exception IO_error is raised when there is an error reading or
writing on a compressed channel ; the string argument is the message
reported by the OS.
exception Data_error
Exception Data_error is raised when a data integrity error is
detected during decompression.
exception Unexpected_EOF
Exception Unexpected_EOF is raised when an in_channel
finishes before the logical end of stream is detected.
When any of these exception is raised, the channel is automatically closed (but you still have to close the Pervasives channel).
val version : stringVersion of the underlying bzip2 library.
val open_in : ?small:bool ->
?unused:bytes -> Stdlib.Pervasives.in_channel -> in_channelopen_in ic opens a compressed stream reading from the
Pervasives input channel ic.
small : when true requests usage of a different method for
decompressing that is slower but uses less memory. Defaults:
falseval read : in_channel -> bytes -> int -> int -> intread buf pos len reads up to len characters and store them in
the string buffer buf, starting at position pos.
End_of_file if end of stream was already reached.len means end of stream).val read_get_unused : in_channel -> bytesIf there's some data after the compressed stream that you want to
read from the same Pervasives in_channel, use
read_get_unused.
val close_in : in_channel -> unitval open_out : ?block:int -> Stdlib.Pervasives.out_channel -> out_channelopen_out oc creates an out_channel writing to the Pervasives
output channel oc. Once the write operations are finished and
the compressed channel is closed, it is possible to continue
writing on the Pervasives channel. However, reading back
requires special care (cf. above).
block : block size to use for compresion. It is a value
between 1 and 9 inclusive. 9 is the default and provides best
compression but takes most memory.val write : out_channel -> bytes -> int -> int -> unitwrite oc buf pos len writes len characters, coming from buf
and starting at position pos, to oc
val close_out : out_channel -> unitThese functions compress to/decompress from string buffers.
val compress : ?block:int -> bytes -> int -> int -> bytescompress buf pos len compress a data chunk coming from buf,
len character long, and starting at pos.
val uncompress : ?small:bool -> bytes -> int -> int -> bytesuncompress buf pos len uncompress a data chunk comfing from
buf, len character long, and starting at pos.
small : see Bz2.open_in above