blob: 7d2cac9d93d0884058fdc3a29e3685ada393d540 [file] [log] [blame]
Guido van Rossumeb0f0661997-12-30 20:38:16 +00001% XXX The module has been extended (by Jeremy) but this documentation hasn't been updated yet
2
Guido van Rossum04bc9d61997-04-30 18:12:27 +00003\section{Built-in Module \sectcode{zlib}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00004\label{module-zlib}
Guido van Rossum04bc9d61997-04-30 18:12:27 +00005\bimodindex{zlib}
6
7For applications that require data compression, the functions in this
Guido van Rossum412154f1997-04-30 19:39:21 +00008module allow compression and decompression, using the zlib library,
9which is based on GNU zip. The zlib library has its own home page at
10\code{http://www.cdrom.com/pub/infozip/zlib/}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +000011Version 1.0.4 is the most recent version as of December, 1997; use a
Guido van Rossum412154f1997-04-30 19:39:21 +000012later version if one is available.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000013
14The available functions in this module are:
15
16\renewcommand{\indexsubitem}{(in module zlib)}
17\begin{funcdesc}{adler32}{string\optional{\, value}}
18 Computes a Adler-32 checksum of \var{string}. (An Adler-32
19 checksum is almost as reliable as a CRC32 but can be computed much
20 more quickly.) If \var{value} is present, it is used as the
21 starting value of the checksum; otherwise, a fixed default value is
22 used. This allows computing a running checksum over the
23 concatenation of several input strings. The algorithm is not
24 cryptographically strong, and should not be used for
25 authentication or digital signatures.
26\end{funcdesc}
27
28\begin{funcdesc}{compress}{string\optional{\, level}}
29Compresses the data in \var{string}, returning a string contained
30compressed data. \var{level} is an integer from 1 to 9 controlling
31the level of compression; 1 is fastest and produces the least
32compression, 9 is slowest and produces the most. The default value is
Guido van Rossum2525bed1997-06-02 17:22:06 +0000336. Raises the \code{zlib.error} exception if any error occurs.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000034\end{funcdesc}
35
36\begin{funcdesc}{compressobj}{\optional{level}}
37Returns a compression object, to be used for compressing data streams
38 that won't fit into memory at once. \var{level} is an integer from
39 1 to 9 controlling the level of compression; 1 is fastest and
40 produces the least compression, 9 is slowest and produces the most.
41 The default value is 6.
42\end{funcdesc}
43
44\begin{funcdesc}{crc32}{string\optional{\, value}}
45 Computes a CRC (Cyclic Redundancy Check) sum of \var{string}. If
46 \var{value} is present, it is used as the starting value of the
47 checksum; otherwise, a fixed default value is used. This allows
48 computing a running checksum over the concatenation of several
49 input strings. The algorithm is not cryptographically strong, and
50 should not be used for authentication or digital signatures.
51\end{funcdesc}
52
53\begin{funcdesc}{decompress}{string}
54Decompresses the data in \var{string}, returning a string containing
55the uncompressed data. Raises the \code{zlib.error} exception if any
56error occurs.
57\end{funcdesc}
58
59\begin{funcdesc}{decompressobj}{\optional{wbits}}
60Returns a compression object, to be used for decompressing data streams
Guido van Rossum412154f1997-04-30 19:39:21 +000061that won't fit into memory at once. The \var{wbits} parameter
62controls the size of the window buffer; usually this can be left
63alone.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000064\end{funcdesc}
65
66Compression objects support the following methods:
67
68\begin{funcdesc}{compress}{string}
69Compress \var{string}, returning a string containing compressed data
70for at least part of the data in \var{string}. This data should be
71concatenated to the output produced by any preceding calls to the
72\code{compress()} method. Some input may be kept in internal buffers
73for later processing.
74\end{funcdesc}
75
76\begin{funcdesc}{flush}{}
77All pending input is processed, and an string containing the remaining
78compressed output is returned. After calling \code{flush()}, the
79\code{compress()} method cannot be called again; the only realistic
80action is to delete the object.
81\end{funcdesc}
82
83Decompression objects support the following methods:
84
85\begin{funcdesc}{decompress}{string}
86Decompress \var{string}, returning a string containing the
87uncompressed data corresponding to at least part of the data in
88\var{string}. This data should be concatenated to the output produced
89by any preceding calls to the
Guido van Rossum412154f1997-04-30 19:39:21 +000090\code{decompress()} method. Some of the input data may be preserved
91in internal buffers for later processing.
Guido van Rossum04bc9d61997-04-30 18:12:27 +000092\end{funcdesc}
93
94\begin{funcdesc}{flush}{}
95All pending input is processed, and a string containing the remaining
96uncompressed output is returned. After calling \code{flush()}, the
97\code{decompress()} method cannot be called again; the only realistic
98action is to delete the object.
99\end{funcdesc}
100
Guido van Rossume47da0a1997-07-17 16:34:52 +0000101\begin{seealso}
102\seemodule{gzip}{reading and writing \file{gzip}-format files}
103\end{seealso}
Guido van Rossum04bc9d61997-04-30 18:12:27 +0000104
105