Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame^] | 1 | % XXX The module has been extended (by Jeremy) but this documentation hasn't been updated yet |
| 2 | |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 3 | \section{Built-in Module \sectcode{zlib}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 4 | \label{module-zlib} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 5 | \bimodindex{zlib} |
| 6 | |
| 7 | For applications that require data compression, the functions in this |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 8 | module allow compression and decompression, using the zlib library, |
| 9 | which 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 Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame^] | 11 | Version 1.0.4 is the most recent version as of December, 1997; use a |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 12 | later version if one is available. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 13 | |
| 14 | The 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}} |
| 29 | Compresses the data in \var{string}, returning a string contained |
| 30 | compressed data. \var{level} is an integer from 1 to 9 controlling |
| 31 | the level of compression; 1 is fastest and produces the least |
| 32 | compression, 9 is slowest and produces the most. The default value is |
Guido van Rossum | 2525bed | 1997-06-02 17:22:06 +0000 | [diff] [blame] | 33 | 6. Raises the \code{zlib.error} exception if any error occurs. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 34 | \end{funcdesc} |
| 35 | |
| 36 | \begin{funcdesc}{compressobj}{\optional{level}} |
| 37 | Returns 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} |
| 54 | Decompresses the data in \var{string}, returning a string containing |
| 55 | the uncompressed data. Raises the \code{zlib.error} exception if any |
| 56 | error occurs. |
| 57 | \end{funcdesc} |
| 58 | |
| 59 | \begin{funcdesc}{decompressobj}{\optional{wbits}} |
| 60 | Returns a compression object, to be used for decompressing data streams |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 61 | that won't fit into memory at once. The \var{wbits} parameter |
| 62 | controls the size of the window buffer; usually this can be left |
| 63 | alone. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 64 | \end{funcdesc} |
| 65 | |
| 66 | Compression objects support the following methods: |
| 67 | |
| 68 | \begin{funcdesc}{compress}{string} |
| 69 | Compress \var{string}, returning a string containing compressed data |
| 70 | for at least part of the data in \var{string}. This data should be |
| 71 | concatenated to the output produced by any preceding calls to the |
| 72 | \code{compress()} method. Some input may be kept in internal buffers |
| 73 | for later processing. |
| 74 | \end{funcdesc} |
| 75 | |
| 76 | \begin{funcdesc}{flush}{} |
| 77 | All pending input is processed, and an string containing the remaining |
| 78 | compressed output is returned. After calling \code{flush()}, the |
| 79 | \code{compress()} method cannot be called again; the only realistic |
| 80 | action is to delete the object. |
| 81 | \end{funcdesc} |
| 82 | |
| 83 | Decompression objects support the following methods: |
| 84 | |
| 85 | \begin{funcdesc}{decompress}{string} |
| 86 | Decompress \var{string}, returning a string containing the |
| 87 | uncompressed data corresponding to at least part of the data in |
| 88 | \var{string}. This data should be concatenated to the output produced |
| 89 | by any preceding calls to the |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 90 | \code{decompress()} method. Some of the input data may be preserved |
| 91 | in internal buffers for later processing. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 92 | \end{funcdesc} |
| 93 | |
| 94 | \begin{funcdesc}{flush}{} |
| 95 | All pending input is processed, and a string containing the remaining |
| 96 | uncompressed output is returned. After calling \code{flush()}, the |
| 97 | \code{decompress()} method cannot be called again; the only realistic |
| 98 | action is to delete the object. |
| 99 | \end{funcdesc} |
| 100 | |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 101 | \begin{seealso} |
| 102 | \seemodule{gzip}{reading and writing \file{gzip}-format files} |
| 103 | \end{seealso} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 104 | |
| 105 | |