blob: 9dbb16b85cc661ed3ac9ec062b34329dc287dc34 [file] [log] [blame]
Fred Drake74810d51998-04-03 06:49:26 +00001% XXX The module has been extended (by Jeremy) but this documentation
Fred Drake08caa961998-07-27 22:08:49 +00002% hasn't been updated completely.
Guido van Rossumeb0f0661997-12-30 20:38:16 +00003
Fred Drake295da241998-08-10 19:42:37 +00004\section{\module{zlib} ---
5 Compression and decompression compatible with \program{gzip}.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006\declaremodule{builtin}{zlib}
7
Fred Drake08caa961998-07-27 22:08:49 +00008\modulesynopsis{Low-level interface to compression and decompression
9routines compatible with \program{gzip}.}
Fred Drakeb91e9341998-07-23 17:59:49 +000010
Guido van Rossum04bc9d61997-04-30 18:12:27 +000011
12For applications that require data compression, the functions in this
Fred Drake8a254b51998-04-09 15:41:44 +000013module allow compression and decompression, using the zlib library.
14The zlib library has its own home page at
Fred Drake74810d51998-04-03 06:49:26 +000015\url{http://www.cdrom.com/pub/infozip/zlib/}. Version 1.0.4 is the
16most recent version as of December, 1997; use a later version if one
17is available.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000018
Fred Drake74810d51998-04-03 06:49:26 +000019The available exception and functions in this module are:
Guido van Rossum04bc9d61997-04-30 18:12:27 +000020
Fred Drake74810d51998-04-03 06:49:26 +000021\begin{excdesc}{error}
22 Exception raised on compression and decompression errors.
23\end{excdesc}
24
25
Fred Drakecce10901998-03-17 06:33:25 +000026\begin{funcdesc}{adler32}{string\optional{, value}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000027 Computes a Adler-32 checksum of \var{string}. (An Adler-32
28 checksum is almost as reliable as a CRC32 but can be computed much
29 more quickly.) If \var{value} is present, it is used as the
30 starting value of the checksum; otherwise, a fixed default value is
31 used. This allows computing a running checksum over the
32 concatenation of several input strings. The algorithm is not
33 cryptographically strong, and should not be used for
34 authentication or digital signatures.
35\end{funcdesc}
36
Fred Drakecce10901998-03-17 06:33:25 +000037\begin{funcdesc}{compress}{string\optional{, level}}
Fred Drake59160701998-06-19 21:18:28 +000038 Compresses the data in \var{string}, returning a string contained
39 compressed data. \var{level} is an integer from \code{1} to
40 \code{9} controlling the level of compression; \code{1} is fastest
41 and produces the least compression, \code{9} is slowest and produces
42 the most. The default value is \code{6}. Raises the
43 \exception{error} exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000044\end{funcdesc}
45
46\begin{funcdesc}{compressobj}{\optional{level}}
Fred Drakeed797831998-01-22 16:11:18 +000047 Returns a compression object, to be used for compressing data streams
Guido van Rossum04bc9d61997-04-30 18:12:27 +000048 that won't fit into memory at once. \var{level} is an integer from
Fred Drakeed797831998-01-22 16:11:18 +000049 \code{1} to \code{9} controlling the level of compression; \code{1} is
50 fastest and produces the least compression, \code{9} is slowest and
51 produces the most. The default value is \code{6}.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000052\end{funcdesc}
53
Fred Drakecce10901998-03-17 06:33:25 +000054\begin{funcdesc}{crc32}{string\optional{, value}}
Fred Drake74810d51998-04-03 06:49:26 +000055 Computes a CRC (Cyclic Redundancy Check)%
56 \index{Cyclic Redundancy Check}
Fred Drakeb208f121998-04-04 06:28:54 +000057 \index{checksum!Cyclic Redundancy Check}
Fred Drake74810d51998-04-03 06:49:26 +000058 checksum of \var{string}. If
59 \var{value} is present, it is used as the starting value of the
60 checksum; otherwise, a fixed default value is used. This allows
61 computing a running checksum over the concatenation of several
62 input strings. The algorithm is not cryptographically strong, and
63 should not be used for authentication or digital signatures.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000064\end{funcdesc}
65
Fred Drake59160701998-06-19 21:18:28 +000066\begin{funcdesc}{decompress}{string\optional{, wbits\optional{, buffsize}}}
67 Decompresses the data in \var{string}, returning a string containing
68 the uncompressed data. The \var{wbits} parameter controls the size of
69 the window buffer. If \var{buffsize} is given, it is used as the
70 initial size of the output buffer. Raises the \exception{error}
71 exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000072\end{funcdesc}
73
74\begin{funcdesc}{decompressobj}{\optional{wbits}}
Fred Drake59160701998-06-19 21:18:28 +000075 Returns a compression object, to be used for decompressing data
76 streams that won't fit into memory at once. The \var{wbits}
77 parameter controls the size of the window buffer.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000078\end{funcdesc}
79
80Compression objects support the following methods:
81
Fred Drake74810d51998-04-03 06:49:26 +000082\begin{methoddesc}[Compress]{compress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000083Compress \var{string}, returning a string containing compressed data
84for at least part of the data in \var{string}. This data should be
85concatenated to the output produced by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +000086\method{compress()} method. Some input may be kept in internal buffers
Guido van Rossum04bc9d61997-04-30 18:12:27 +000087for later processing.
Fred Drake74810d51998-04-03 06:49:26 +000088\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000089
Fred Drake74810d51998-04-03 06:49:26 +000090\begin{methoddesc}[Compress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000091All pending input is processed, and an string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +000092compressed output is returned. After calling \method{flush()}, the
93\method{compress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +000094action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +000095\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000096
97Decompression objects support the following methods:
98
Fred Drake74810d51998-04-03 06:49:26 +000099\begin{methoddesc}[Decompress]{decompress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000100Decompress \var{string}, returning a string containing the
101uncompressed data corresponding to at least part of the data in
102\var{string}. This data should be concatenated to the output produced
103by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +0000104\method{decompress()} method. Some of the input data may be preserved
Guido van Rossum412154f1997-04-30 19:39:21 +0000105in internal buffers for later processing.
Fred Drake74810d51998-04-03 06:49:26 +0000106\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000107
Fred Drake74810d51998-04-03 06:49:26 +0000108\begin{methoddesc}[Decompress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000109All pending input is processed, and a string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +0000110uncompressed output is returned. After calling \method{flush()}, the
111\method{decompress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000112action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +0000113\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000114
Guido van Rossume47da0a1997-07-17 16:34:52 +0000115\begin{seealso}
Fred Drake74810d51998-04-03 06:49:26 +0000116\seemodule{gzip}{reading and writing \program{gzip}-format files}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000117\end{seealso}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000118
119