Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{zlib}} |
| 2 | \bimodindex{zlib} |
| 3 | |
| 4 | For applications that require data compression, the functions in this |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 5 | module allow compression and decompression, using the zlib library, |
| 6 | which is based on GNU zip. The zlib library has its own home page at |
| 7 | \code{http://www.cdrom.com/pub/infozip/zlib/}. |
| 8 | Version 1.0.4 is the most recent version as of April 30, 1997; use a |
| 9 | later version if one is available. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 10 | |
| 11 | The 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}} |
| 26 | Compresses the data in \var{string}, returning a string contained |
| 27 | compressed data. \var{level} is an integer from 1 to 9 controlling |
| 28 | the level of compression; 1 is fastest and produces the least |
| 29 | 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] | 30 | 6. Raises the \code{zlib.error} exception if any error occurs. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 31 | \end{funcdesc} |
| 32 | |
| 33 | \begin{funcdesc}{compressobj}{\optional{level}} |
| 34 | Returns 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} |
| 51 | Decompresses the data in \var{string}, returning a string containing |
| 52 | the uncompressed data. Raises the \code{zlib.error} exception if any |
| 53 | error occurs. |
| 54 | \end{funcdesc} |
| 55 | |
| 56 | \begin{funcdesc}{decompressobj}{\optional{wbits}} |
| 57 | Returns a compression object, to be used for decompressing data streams |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 58 | that won't fit into memory at once. The \var{wbits} parameter |
| 59 | controls the size of the window buffer; usually this can be left |
| 60 | alone. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 61 | \end{funcdesc} |
| 62 | |
| 63 | Compression objects support the following methods: |
| 64 | |
| 65 | \begin{funcdesc}{compress}{string} |
| 66 | Compress \var{string}, returning a string containing compressed data |
| 67 | for at least part of the data in \var{string}. This data should be |
| 68 | concatenated to the output produced by any preceding calls to the |
| 69 | \code{compress()} method. Some input may be kept in internal buffers |
| 70 | for later processing. |
| 71 | \end{funcdesc} |
| 72 | |
| 73 | \begin{funcdesc}{flush}{} |
| 74 | All pending input is processed, and an string containing the remaining |
| 75 | compressed output is returned. After calling \code{flush()}, the |
| 76 | \code{compress()} method cannot be called again; the only realistic |
| 77 | action is to delete the object. |
| 78 | \end{funcdesc} |
| 79 | |
| 80 | Decompression objects support the following methods: |
| 81 | |
| 82 | \begin{funcdesc}{decompress}{string} |
| 83 | Decompress \var{string}, returning a string containing the |
| 84 | uncompressed data corresponding to at least part of the data in |
| 85 | \var{string}. This data should be concatenated to the output produced |
| 86 | by any preceding calls to the |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 87 | \code{decompress()} method. Some of the input data may be preserved |
| 88 | in internal buffers for later processing. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 89 | \end{funcdesc} |
| 90 | |
| 91 | \begin{funcdesc}{flush}{} |
| 92 | All pending input is processed, and a string containing the remaining |
| 93 | uncompressed output is returned. After calling \code{flush()}, the |
| 94 | \code{decompress()} method cannot be called again; the only realistic |
| 95 | action is to delete the object. |
| 96 | \end{funcdesc} |
| 97 | |
| 98 | |
| 99 | |