blob: 718a3d4511ff9e3032b2dd483d3e8b70d4e1957b [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}}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\declaremodule{builtin}{zlib}
6
7\modulesynopsis{None}
8
Guido van Rossum04bc9d61997-04-30 18:12:27 +00009
10For applications that require data compression, the functions in this
Fred Drake8a254b51998-04-09 15:41:44 +000011module allow compression and decompression, using the zlib library.
12The zlib library has its own home page at
Fred Drake74810d51998-04-03 06:49:26 +000013\url{http://www.cdrom.com/pub/infozip/zlib/}. Version 1.0.4 is the
14most recent version as of December, 1997; use a later version if one
15is available.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000016
Fred Drake74810d51998-04-03 06:49:26 +000017The available exception and functions in this module are:
Guido van Rossum04bc9d61997-04-30 18:12:27 +000018
Fred Drake74810d51998-04-03 06:49:26 +000019\begin{excdesc}{error}
20 Exception raised on compression and decompression errors.
21\end{excdesc}
22
23
Fred Drakecce10901998-03-17 06:33:25 +000024\begin{funcdesc}{adler32}{string\optional{, value}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000025 Computes a Adler-32 checksum of \var{string}. (An Adler-32
26 checksum is almost as reliable as a CRC32 but can be computed much
27 more quickly.) If \var{value} is present, it is used as the
28 starting value of the checksum; otherwise, a fixed default value is
29 used. This allows computing a running checksum over the
30 concatenation of several input strings. The algorithm is not
31 cryptographically strong, and should not be used for
32 authentication or digital signatures.
33\end{funcdesc}
34
Fred Drakecce10901998-03-17 06:33:25 +000035\begin{funcdesc}{compress}{string\optional{, level}}
Fred Drake59160701998-06-19 21:18:28 +000036 Compresses the data in \var{string}, returning a string contained
37 compressed data. \var{level} is an integer from \code{1} to
38 \code{9} controlling the level of compression; \code{1} is fastest
39 and produces the least compression, \code{9} is slowest and produces
40 the most. The default value is \code{6}. Raises the
41 \exception{error} exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000042\end{funcdesc}
43
44\begin{funcdesc}{compressobj}{\optional{level}}
Fred Drakeed797831998-01-22 16:11:18 +000045 Returns a compression object, to be used for compressing data streams
Guido van Rossum04bc9d61997-04-30 18:12:27 +000046 that won't fit into memory at once. \var{level} is an integer from
Fred Drakeed797831998-01-22 16:11:18 +000047 \code{1} to \code{9} controlling the level of compression; \code{1} is
48 fastest and produces the least compression, \code{9} is slowest and
49 produces the most. The default value is \code{6}.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000050\end{funcdesc}
51
Fred Drakecce10901998-03-17 06:33:25 +000052\begin{funcdesc}{crc32}{string\optional{, value}}
Fred Drake74810d51998-04-03 06:49:26 +000053 Computes a CRC (Cyclic Redundancy Check)%
54 \index{Cyclic Redundancy Check}
Fred Drakeb208f121998-04-04 06:28:54 +000055 \index{checksum!Cyclic Redundancy Check}
Fred Drake74810d51998-04-03 06:49:26 +000056 checksum of \var{string}. If
57 \var{value} is present, it is used as the starting value of the
58 checksum; otherwise, a fixed default value is used. This allows
59 computing a running checksum over the concatenation of several
60 input strings. The algorithm is not cryptographically strong, and
61 should not be used for authentication or digital signatures.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000062\end{funcdesc}
63
Fred Drake59160701998-06-19 21:18:28 +000064\begin{funcdesc}{decompress}{string\optional{, wbits\optional{, buffsize}}}
65 Decompresses the data in \var{string}, returning a string containing
66 the uncompressed data. The \var{wbits} parameter controls the size of
67 the window buffer. If \var{buffsize} is given, it is used as the
68 initial size of the output buffer. Raises the \exception{error}
69 exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000070\end{funcdesc}
71
72\begin{funcdesc}{decompressobj}{\optional{wbits}}
Fred Drake59160701998-06-19 21:18:28 +000073 Returns a compression object, to be used for decompressing data
74 streams that won't fit into memory at once. The \var{wbits}
75 parameter controls the size of the window buffer.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000076\end{funcdesc}
77
78Compression objects support the following methods:
79
Fred Drake74810d51998-04-03 06:49:26 +000080\begin{methoddesc}[Compress]{compress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000081Compress \var{string}, returning a string containing compressed data
82for at least part of the data in \var{string}. This data should be
83concatenated to the output produced by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +000084\method{compress()} method. Some input may be kept in internal buffers
Guido van Rossum04bc9d61997-04-30 18:12:27 +000085for later processing.
Fred Drake74810d51998-04-03 06:49:26 +000086\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000087
Fred Drake74810d51998-04-03 06:49:26 +000088\begin{methoddesc}[Compress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000089All pending input is processed, and an string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +000090compressed output is returned. After calling \method{flush()}, the
91\method{compress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +000092action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +000093\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000094
95Decompression objects support the following methods:
96
Fred Drake74810d51998-04-03 06:49:26 +000097\begin{methoddesc}[Decompress]{decompress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000098Decompress \var{string}, returning a string containing the
99uncompressed data corresponding to at least part of the data in
100\var{string}. This data should be concatenated to the output produced
101by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +0000102\method{decompress()} method. Some of the input data may be preserved
Guido van Rossum412154f1997-04-30 19:39:21 +0000103in internal buffers for later processing.
Fred Drake74810d51998-04-03 06:49:26 +0000104\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000105
Fred Drake74810d51998-04-03 06:49:26 +0000106\begin{methoddesc}[Decompress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000107All pending input is processed, and a string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +0000108uncompressed output is returned. After calling \method{flush()}, the
109\method{decompress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000110action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +0000111\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000112
Guido van Rossume47da0a1997-07-17 16:34:52 +0000113\begin{seealso}
Fred Drake74810d51998-04-03 06:49:26 +0000114\seemodule{gzip}{reading and writing \program{gzip}-format files}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000115\end{seealso}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000116
117