Module Bz

module Bz: sig .. end
Bzip2 interface

The module Bz provides a very basic interface to the bzip2 compression library.

Datatypes & exceptions

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 : string

Input functions

val open_in : ?small:bool -> ?unused:string -> Pervasives.in_channel -> in_channel
open_in opens a compressed stream that is located on a Pervasives channel.
small : defaults to false ; when true it uses a different method for decompressing that is slower but uses less memory.
val read : in_channel -> buf:string -> pos:int -> len:int -> int
read reads len characters in a string buffer.
Raises End_of_file if end of stream was already reached.
Returns number of bytes actually read, (a value less than len means end of stream).
val read_get_unused : in_channel -> string
If 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 -> unit

Output funcions

val open_out : ?block:int -> Pervasives.out_channel -> out_channel
open_out creates an out_channel from a Pervasives channel. 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 -> buf:string -> pos:int -> len:int -> unit
val close_out : out_channel -> unit

In-memory compression

These functions compress & decompress to and from string buffers.
val compress : ?block:int -> string -> pos:int -> len:int -> string
val uncompress : ?small:bool -> string -> pos:int -> len:int -> string