blob: f38a21cd5cd1f6b13b58cbee6a9c49d9f044a61b [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
Fred Drake8a254b51998-04-09 15:41:44 +00009module allow compression and decompression, using the zlib library.
10The zlib library has its own home page at
Fred Drake74810d51998-04-03 06:49:26 +000011\url{http://www.cdrom.com/pub/infozip/zlib/}. Version 1.0.4 is the
12most recent version as of December, 1997; use a later version if one
13is available.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000014
Fred Drake74810d51998-04-03 06:49:26 +000015The available exception and functions in this module are:
Guido van Rossum04bc9d61997-04-30 18:12:27 +000016
Fred Drake74810d51998-04-03 06:49:26 +000017\begin{excdesc}{error}
18 Exception raised on compression and decompression errors.
19\end{excdesc}
20
21
Fred Drakecce10901998-03-17 06:33:25 +000022\begin{funcdesc}{adler32}{string\optional{, value}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000023 Computes a Adler-32 checksum of \var{string}. (An Adler-32
24 checksum is almost as reliable as a CRC32 but can be computed much
25 more quickly.) If \var{value} is present, it is used as the
26 starting value of the checksum; otherwise, a fixed default value is
27 used. This allows computing a running checksum over the
28 concatenation of several input strings. The algorithm is not
29 cryptographically strong, and should not be used for
30 authentication or digital signatures.
31\end{funcdesc}
32
Fred Drakecce10901998-03-17 06:33:25 +000033\begin{funcdesc}{compress}{string\optional{, level}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000034Compresses the data in \var{string}, returning a string contained
Fred Drakeed797831998-01-22 16:11:18 +000035compressed data. \var{level} is an integer from \code{1} to \code{9}
36controlling the level of compression; \code{1} is fastest and produces
37the least compression, \code{9} is slowest and produces the most. The
Fred Drake74810d51998-04-03 06:49:26 +000038default value is \code{6}. Raises the \exception{error}
Fred Drakeed797831998-01-22 16:11:18 +000039exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000040\end{funcdesc}
41
42\begin{funcdesc}{compressobj}{\optional{level}}
Fred Drakeed797831998-01-22 16:11:18 +000043 Returns a compression object, to be used for compressing data streams
Guido van Rossum04bc9d61997-04-30 18:12:27 +000044 that won't fit into memory at once. \var{level} is an integer from
Fred Drakeed797831998-01-22 16:11:18 +000045 \code{1} to \code{9} controlling the level of compression; \code{1} is
46 fastest and produces the least compression, \code{9} is slowest and
47 produces the most. The default value is \code{6}.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000048\end{funcdesc}
49
Fred Drakecce10901998-03-17 06:33:25 +000050\begin{funcdesc}{crc32}{string\optional{, value}}
Fred Drake74810d51998-04-03 06:49:26 +000051 Computes a CRC (Cyclic Redundancy Check)%
52 \index{Cyclic Redundancy Check}
Fred Drakeb208f121998-04-04 06:28:54 +000053 \index{checksum!Cyclic Redundancy Check}
Fred Drake74810d51998-04-03 06:49:26 +000054 checksum of \var{string}. If
55 \var{value} is present, it is used as the starting value of the
56 checksum; otherwise, a fixed default value is used. This allows
57 computing a running checksum over the concatenation of several
58 input strings. The algorithm is not cryptographically strong, and
59 should not be used for authentication or digital signatures.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000060\end{funcdesc}
61
62\begin{funcdesc}{decompress}{string}
63Decompresses the data in \var{string}, returning a string containing
Fred Drake74810d51998-04-03 06:49:26 +000064the uncompressed data. Raises the \exception{error} exception if any
Guido van Rossum04bc9d61997-04-30 18:12:27 +000065error occurs.
66\end{funcdesc}
67
68\begin{funcdesc}{decompressobj}{\optional{wbits}}
69Returns a compression object, to be used for decompressing data streams
Guido van Rossum412154f1997-04-30 19:39:21 +000070that won't fit into memory at once. The \var{wbits} parameter
71controls the size of the window buffer; usually this can be left
72alone.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000073\end{funcdesc}
74
75Compression objects support the following methods:
76
Fred Drake74810d51998-04-03 06:49:26 +000077\begin{methoddesc}[Compress]{compress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000078Compress \var{string}, returning a string containing compressed data
79for at least part of the data in \var{string}. This data should be
80concatenated to the output produced by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +000081\method{compress()} method. Some input may be kept in internal buffers
Guido van Rossum04bc9d61997-04-30 18:12:27 +000082for later processing.
Fred Drake74810d51998-04-03 06:49:26 +000083\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000084
Fred Drake74810d51998-04-03 06:49:26 +000085\begin{methoddesc}[Compress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000086All pending input is processed, and an string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +000087compressed output is returned. After calling \method{flush()}, the
88\method{compress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +000089action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +000090\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000091
92Decompression objects support the following methods:
93
Fred Drake74810d51998-04-03 06:49:26 +000094\begin{methoddesc}[Decompress]{decompress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000095Decompress \var{string}, returning a string containing the
96uncompressed data corresponding to at least part of the data in
97\var{string}. This data should be concatenated to the output produced
98by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +000099\method{decompress()} method. Some of the input data may be preserved
Guido van Rossum412154f1997-04-30 19:39:21 +0000100in internal buffers for later processing.
Fred Drake74810d51998-04-03 06:49:26 +0000101\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000102
Fred Drake74810d51998-04-03 06:49:26 +0000103\begin{methoddesc}[Decompress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000104All pending input is processed, and a string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +0000105uncompressed output is returned. After calling \method{flush()}, the
106\method{decompress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000107action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +0000108\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000109
Guido van Rossume47da0a1997-07-17 16:34:52 +0000110\begin{seealso}
Fred Drake74810d51998-04-03 06:49:26 +0000111\seemodule{gzip}{reading and writing \program{gzip}-format files}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000112\end{seealso}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000113
114