blob: 2e76900b6aa927620630f0d27ef23ce370a63636 [file] [log] [blame]
Fred Drake74810d51998-04-03 06:49:26 +00001% XXX The module has been extended (by Jeremy) but this documentation
2% hasn't been updated yet
Guido van Rossumeb0f0661997-12-30 20:38:16 +00003
Fred Drake74810d51998-04-03 06:49:26 +00004\section{Built-in Module \module{zlib}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00005\label{module-zlib}
Guido van Rossum04bc9d61997-04-30 18:12:27 +00006\bimodindex{zlib}
7
8For applications that require data compression, the functions in this
Guido van Rossum412154f1997-04-30 19:39:21 +00009module allow compression and decompression, using the zlib library,
Fred Drake74810d51998-04-03 06:49:26 +000010which is based on the GNU \program{gzip} program. The zlib library
11has its own home page at
12\url{http://www.cdrom.com/pub/infozip/zlib/}. Version 1.0.4 is the
13most recent version as of December, 1997; use a later version if one
14is available.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000015
Fred Drake74810d51998-04-03 06:49:26 +000016The available exception and functions in this module are:
Guido van Rossum04bc9d61997-04-30 18:12:27 +000017
Fred Drake74810d51998-04-03 06:49:26 +000018\begin{excdesc}{error}
19 Exception raised on compression and decompression errors.
20\end{excdesc}
21
22
Fred Drakecce10901998-03-17 06:33:25 +000023\begin{funcdesc}{adler32}{string\optional{, value}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000024 Computes a Adler-32 checksum of \var{string}. (An Adler-32
25 checksum is almost as reliable as a CRC32 but can be computed much
26 more quickly.) If \var{value} is present, it is used as the
27 starting value of the checksum; otherwise, a fixed default value is
28 used. This allows computing a running checksum over the
29 concatenation of several input strings. The algorithm is not
30 cryptographically strong, and should not be used for
31 authentication or digital signatures.
32\end{funcdesc}
33
Fred Drakecce10901998-03-17 06:33:25 +000034\begin{funcdesc}{compress}{string\optional{, level}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000035Compresses the data in \var{string}, returning a string contained
Fred Drakeed797831998-01-22 16:11:18 +000036compressed data. \var{level} is an integer from \code{1} to \code{9}
37controlling the level of compression; \code{1} is fastest and produces
38the least compression, \code{9} is slowest and produces the most. The
Fred Drake74810d51998-04-03 06:49:26 +000039default value is \code{6}. Raises the \exception{error}
Fred Drakeed797831998-01-22 16:11:18 +000040exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000041\end{funcdesc}
42
43\begin{funcdesc}{compressobj}{\optional{level}}
Fred Drakeed797831998-01-22 16:11:18 +000044 Returns a compression object, to be used for compressing data streams
Guido van Rossum04bc9d61997-04-30 18:12:27 +000045 that won't fit into memory at once. \var{level} is an integer from
Fred Drakeed797831998-01-22 16:11:18 +000046 \code{1} to \code{9} controlling the level of compression; \code{1} is
47 fastest and produces the least compression, \code{9} is slowest and
48 produces the most. The default value is \code{6}.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000049\end{funcdesc}
50
Fred Drakecce10901998-03-17 06:33:25 +000051\begin{funcdesc}{crc32}{string\optional{, value}}
Fred Drake74810d51998-04-03 06:49:26 +000052 Computes a CRC (Cyclic Redundancy Check)%
53 \index{Cyclic Redundancy Check}
Fred Drakeb208f121998-04-04 06:28:54 +000054 \index{checksum!Cyclic Redundancy Check}
Fred Drake74810d51998-04-03 06:49:26 +000055 checksum of \var{string}. If
56 \var{value} is present, it is used as the starting value of the
57 checksum; otherwise, a fixed default value is used. This allows
58 computing a running checksum over the concatenation of several
59 input strings. The algorithm is not cryptographically strong, and
60 should not be used for authentication or digital signatures.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000061\end{funcdesc}
62
63\begin{funcdesc}{decompress}{string}
64Decompresses the data in \var{string}, returning a string containing
Fred Drake74810d51998-04-03 06:49:26 +000065the uncompressed data. Raises the \exception{error} exception if any
Guido van Rossum04bc9d61997-04-30 18:12:27 +000066error occurs.
67\end{funcdesc}
68
69\begin{funcdesc}{decompressobj}{\optional{wbits}}
70Returns a compression object, to be used for decompressing data streams
Guido van Rossum412154f1997-04-30 19:39:21 +000071that won't fit into memory at once. The \var{wbits} parameter
72controls the size of the window buffer; usually this can be left
73alone.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000074\end{funcdesc}
75
76Compression objects support the following methods:
77
Fred Drake74810d51998-04-03 06:49:26 +000078\begin{methoddesc}[Compress]{compress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000079Compress \var{string}, returning a string containing compressed data
80for at least part of the data in \var{string}. This data should be
81concatenated to the output produced by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +000082\method{compress()} method. Some input may be kept in internal buffers
Guido van Rossum04bc9d61997-04-30 18:12:27 +000083for later processing.
Fred Drake74810d51998-04-03 06:49:26 +000084\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000085
Fred Drake74810d51998-04-03 06:49:26 +000086\begin{methoddesc}[Compress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000087All pending input is processed, and an string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +000088compressed output is returned. After calling \method{flush()}, the
89\method{compress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +000090action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +000091\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000092
93Decompression objects support the following methods:
94
Fred Drake74810d51998-04-03 06:49:26 +000095\begin{methoddesc}[Decompress]{decompress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000096Decompress \var{string}, returning a string containing the
97uncompressed data corresponding to at least part of the data in
98\var{string}. This data should be concatenated to the output produced
99by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +0000100\method{decompress()} method. Some of the input data may be preserved
Guido van Rossum412154f1997-04-30 19:39:21 +0000101in internal buffers for later processing.
Fred Drake74810d51998-04-03 06:49:26 +0000102\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000103
Fred Drake74810d51998-04-03 06:49:26 +0000104\begin{methoddesc}[Decompress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000105All pending input is processed, and a string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +0000106uncompressed output is returned. After calling \method{flush()}, the
107\method{decompress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000108action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +0000109\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000110
Guido van Rossume47da0a1997-07-17 16:34:52 +0000111\begin{seealso}
Fred Drake74810d51998-04-03 06:49:26 +0000112\seemodule{gzip}{reading and writing \program{gzip}-format files}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000113\end{seealso}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000114
115