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