blob: 0369507535e83556cc342c2cf7d20cfca8023164 [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 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
Fred Drake08caa961998-07-27 22:08:49 +00007\modulesynopsis{Low-level interface to compression and decompression
8routines compatible with \program{gzip}.}
Fred Drakeb91e9341998-07-23 17:59:49 +00009
Guido van Rossum04bc9d61997-04-30 18:12:27 +000010
11For applications that require data compression, the functions in this
Fred Drake8a254b51998-04-09 15:41:44 +000012module allow compression and decompression, using the zlib library.
13The zlib library has its own home page at
Fred Drake74810d51998-04-03 06:49:26 +000014\url{http://www.cdrom.com/pub/infozip/zlib/}. Version 1.0.4 is the
15most recent version as of December, 1997; use a later version if one
16is available.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000017
Fred Drake74810d51998-04-03 06:49:26 +000018The available exception and functions in this module are:
Guido van Rossum04bc9d61997-04-30 18:12:27 +000019
Fred Drake74810d51998-04-03 06:49:26 +000020\begin{excdesc}{error}
21 Exception raised on compression and decompression errors.
22\end{excdesc}
23
24
Fred Drakecce10901998-03-17 06:33:25 +000025\begin{funcdesc}{adler32}{string\optional{, value}}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000026 Computes a Adler-32 checksum of \var{string}. (An Adler-32
27 checksum is almost as reliable as a CRC32 but can be computed much
28 more quickly.) If \var{value} is present, it is used as the
29 starting value of the checksum; otherwise, a fixed default value is
30 used. This allows computing a running checksum over the
31 concatenation of several input strings. The algorithm is not
32 cryptographically strong, and should not be used for
33 authentication or digital signatures.
34\end{funcdesc}
35
Fred Drakecce10901998-03-17 06:33:25 +000036\begin{funcdesc}{compress}{string\optional{, level}}
Fred Drake59160701998-06-19 21:18:28 +000037 Compresses the data in \var{string}, returning a string contained
38 compressed data. \var{level} is an integer from \code{1} to
39 \code{9} controlling the level of compression; \code{1} is fastest
40 and produces the least compression, \code{9} is slowest and produces
41 the most. The default value is \code{6}. Raises the
42 \exception{error} exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000043\end{funcdesc}
44
45\begin{funcdesc}{compressobj}{\optional{level}}
Fred Drakeed797831998-01-22 16:11:18 +000046 Returns a compression object, to be used for compressing data streams
Guido van Rossum04bc9d61997-04-30 18:12:27 +000047 that won't fit into memory at once. \var{level} is an integer from
Fred Drakeed797831998-01-22 16:11:18 +000048 \code{1} to \code{9} controlling the level of compression; \code{1} is
49 fastest and produces the least compression, \code{9} is slowest and
50 produces the most. The default value is \code{6}.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000051\end{funcdesc}
52
Fred Drakecce10901998-03-17 06:33:25 +000053\begin{funcdesc}{crc32}{string\optional{, value}}
Fred Drake74810d51998-04-03 06:49:26 +000054 Computes a CRC (Cyclic Redundancy Check)%
55 \index{Cyclic Redundancy Check}
Fred Drakeb208f121998-04-04 06:28:54 +000056 \index{checksum!Cyclic Redundancy Check}
Fred Drake74810d51998-04-03 06:49:26 +000057 checksum of \var{string}. If
58 \var{value} is present, it is used as the starting value of the
59 checksum; otherwise, a fixed default value is used. This allows
60 computing a running checksum over the concatenation of several
61 input strings. The algorithm is not cryptographically strong, and
62 should not be used for authentication or digital signatures.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000063\end{funcdesc}
64
Fred Drake59160701998-06-19 21:18:28 +000065\begin{funcdesc}{decompress}{string\optional{, wbits\optional{, buffsize}}}
66 Decompresses the data in \var{string}, returning a string containing
67 the uncompressed data. The \var{wbits} parameter controls the size of
68 the window buffer. If \var{buffsize} is given, it is used as the
69 initial size of the output buffer. Raises the \exception{error}
70 exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000071\end{funcdesc}
72
73\begin{funcdesc}{decompressobj}{\optional{wbits}}
Fred Drake59160701998-06-19 21:18:28 +000074 Returns a compression object, to be used for decompressing data
75 streams that won't fit into memory at once. The \var{wbits}
76 parameter controls the size of the window buffer.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000077\end{funcdesc}
78
79Compression objects support the following methods:
80
Fred Drake74810d51998-04-03 06:49:26 +000081\begin{methoddesc}[Compress]{compress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000082Compress \var{string}, returning a string containing compressed data
83for at least part of the data in \var{string}. This data should be
84concatenated to the output produced by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +000085\method{compress()} method. Some input may be kept in internal buffers
Guido van Rossum04bc9d61997-04-30 18:12:27 +000086for later processing.
Fred Drake74810d51998-04-03 06:49:26 +000087\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000088
Fred Drake74810d51998-04-03 06:49:26 +000089\begin{methoddesc}[Compress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000090All pending input is processed, and an string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +000091compressed output is returned. After calling \method{flush()}, the
92\method{compress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +000093action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +000094\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000095
96Decompression objects support the following methods:
97
Fred Drake74810d51998-04-03 06:49:26 +000098\begin{methoddesc}[Decompress]{decompress}{string}
Guido van Rossum04bc9d61997-04-30 18:12:27 +000099Decompress \var{string}, returning a string containing the
100uncompressed data corresponding to at least part of the data in
101\var{string}. This data should be concatenated to the output produced
102by any preceding calls to the
Fred Drakeed797831998-01-22 16:11:18 +0000103\method{decompress()} method. Some of the input data may be preserved
Guido van Rossum412154f1997-04-30 19:39:21 +0000104in internal buffers for later processing.
Fred Drake74810d51998-04-03 06:49:26 +0000105\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000106
Fred Drake74810d51998-04-03 06:49:26 +0000107\begin{methoddesc}[Decompress]{flush}{}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000108All pending input is processed, and a string containing the remaining
Fred Drakeed797831998-01-22 16:11:18 +0000109uncompressed output is returned. After calling \method{flush()}, the
110\method{decompress()} method cannot be called again; the only realistic
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000111action is to delete the object.
Fred Drake74810d51998-04-03 06:49:26 +0000112\end{methoddesc}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000113
Guido van Rossume47da0a1997-07-17 16:34:52 +0000114\begin{seealso}
Fred Drake74810d51998-04-03 06:49:26 +0000115\seemodule{gzip}{reading and writing \program{gzip}-format files}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000116\end{seealso}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000117
118