Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 1 | % XXX The module has been extended (by Jeremy) but this documentation |
Fred Drake | 08caa96 | 1998-07-27 22:08:49 +0000 | [diff] [blame] | 2 | % hasn't been updated completely. |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 3 | |
Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 4 | \section{\module{zlib} --- |
| 5 | Compression and decompression compatible with \program{gzip}.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 6 | \declaremodule{builtin}{zlib} |
| 7 | |
Fred Drake | 08caa96 | 1998-07-27 22:08:49 +0000 | [diff] [blame] | 8 | \modulesynopsis{Low-level interface to compression and decompression |
| 9 | routines compatible with \program{gzip}.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 11 | |
| 12 | For applications that require data compression, the functions in this |
Fred Drake | 8a254b5 | 1998-04-09 15:41:44 +0000 | [diff] [blame] | 13 | module allow compression and decompression, using the zlib library. |
| 14 | The zlib library has its own home page at |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 15 | \url{http://www.cdrom.com/pub/infozip/zlib/}. Version 1.0.4 is the |
| 16 | most recent version as of December, 1997; use a later version if one |
| 17 | is available. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 18 | |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 19 | The available exception and functions in this module are: |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 20 | |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 21 | \begin{excdesc}{error} |
| 22 | Exception raised on compression and decompression errors. |
| 23 | \end{excdesc} |
| 24 | |
| 25 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 26 | \begin{funcdesc}{adler32}{string\optional{, value}} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 27 | Computes a Adler-32 checksum of \var{string}. (An Adler-32 |
| 28 | checksum is almost as reliable as a CRC32 but can be computed much |
| 29 | more quickly.) If \var{value} is present, it is used as the |
| 30 | starting value of the checksum; otherwise, a fixed default value is |
| 31 | used. This allows computing a running checksum over the |
| 32 | concatenation of several input strings. The algorithm is not |
| 33 | cryptographically strong, and should not be used for |
| 34 | authentication or digital signatures. |
| 35 | \end{funcdesc} |
| 36 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 37 | \begin{funcdesc}{compress}{string\optional{, level}} |
Fred Drake | 5916070 | 1998-06-19 21:18:28 +0000 | [diff] [blame] | 38 | Compresses the data in \var{string}, returning a string contained |
| 39 | compressed data. \var{level} is an integer from \code{1} to |
| 40 | \code{9} controlling the level of compression; \code{1} is fastest |
| 41 | and produces the least compression, \code{9} is slowest and produces |
| 42 | the most. The default value is \code{6}. Raises the |
| 43 | \exception{error} exception if any error occurs. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 44 | \end{funcdesc} |
| 45 | |
| 46 | \begin{funcdesc}{compressobj}{\optional{level}} |
Fred Drake | ed79783 | 1998-01-22 16:11:18 +0000 | [diff] [blame] | 47 | Returns a compression object, to be used for compressing data streams |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 48 | that won't fit into memory at once. \var{level} is an integer from |
Fred Drake | ed79783 | 1998-01-22 16:11:18 +0000 | [diff] [blame] | 49 | \code{1} to \code{9} controlling the level of compression; \code{1} is |
| 50 | fastest and produces the least compression, \code{9} is slowest and |
| 51 | produces the most. The default value is \code{6}. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 52 | \end{funcdesc} |
| 53 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 54 | \begin{funcdesc}{crc32}{string\optional{, value}} |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 55 | Computes a CRC (Cyclic Redundancy Check)% |
| 56 | \index{Cyclic Redundancy Check} |
Fred Drake | b208f12 | 1998-04-04 06:28:54 +0000 | [diff] [blame] | 57 | \index{checksum!Cyclic Redundancy Check} |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 58 | checksum of \var{string}. If |
| 59 | \var{value} is present, it is used as the starting value of the |
| 60 | checksum; otherwise, a fixed default value is used. This allows |
| 61 | computing a running checksum over the concatenation of several |
| 62 | input strings. The algorithm is not cryptographically strong, and |
| 63 | should not be used for authentication or digital signatures. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 64 | \end{funcdesc} |
| 65 | |
Fred Drake | 5916070 | 1998-06-19 21:18:28 +0000 | [diff] [blame] | 66 | \begin{funcdesc}{decompress}{string\optional{, wbits\optional{, buffsize}}} |
| 67 | Decompresses the data in \var{string}, returning a string containing |
| 68 | the uncompressed data. The \var{wbits} parameter controls the size of |
| 69 | the window buffer. If \var{buffsize} is given, it is used as the |
| 70 | initial size of the output buffer. Raises the \exception{error} |
| 71 | exception if any error occurs. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 72 | \end{funcdesc} |
| 73 | |
| 74 | \begin{funcdesc}{decompressobj}{\optional{wbits}} |
Fred Drake | 5916070 | 1998-06-19 21:18:28 +0000 | [diff] [blame] | 75 | Returns a compression object, to be used for decompressing data |
| 76 | streams that won't fit into memory at once. The \var{wbits} |
| 77 | parameter controls the size of the window buffer. |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 78 | \end{funcdesc} |
| 79 | |
| 80 | Compression objects support the following methods: |
| 81 | |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 82 | \begin{methoddesc}[Compress]{compress}{string} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 83 | Compress \var{string}, returning a string containing compressed data |
| 84 | for at least part of the data in \var{string}. This data should be |
| 85 | concatenated to the output produced by any preceding calls to the |
Fred Drake | ed79783 | 1998-01-22 16:11:18 +0000 | [diff] [blame] | 86 | \method{compress()} method. Some input may be kept in internal buffers |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 87 | for later processing. |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 88 | \end{methoddesc} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 89 | |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 90 | \begin{methoddesc}[Compress]{flush}{} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 91 | All pending input is processed, and an string containing the remaining |
Fred Drake | ed79783 | 1998-01-22 16:11:18 +0000 | [diff] [blame] | 92 | compressed output is returned. After calling \method{flush()}, the |
| 93 | \method{compress()} method cannot be called again; the only realistic |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 94 | action is to delete the object. |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 95 | \end{methoddesc} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 96 | |
| 97 | Decompression objects support the following methods: |
| 98 | |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 99 | \begin{methoddesc}[Decompress]{decompress}{string} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 100 | Decompress \var{string}, returning a string containing the |
| 101 | uncompressed data corresponding to at least part of the data in |
| 102 | \var{string}. This data should be concatenated to the output produced |
| 103 | by any preceding calls to the |
Fred Drake | ed79783 | 1998-01-22 16:11:18 +0000 | [diff] [blame] | 104 | \method{decompress()} method. Some of the input data may be preserved |
Guido van Rossum | 412154f | 1997-04-30 19:39:21 +0000 | [diff] [blame] | 105 | in internal buffers for later processing. |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 106 | \end{methoddesc} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 107 | |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 108 | \begin{methoddesc}[Decompress]{flush}{} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 109 | All pending input is processed, and a string containing the remaining |
Fred Drake | ed79783 | 1998-01-22 16:11:18 +0000 | [diff] [blame] | 110 | uncompressed output is returned. After calling \method{flush()}, the |
| 111 | \method{decompress()} method cannot be called again; the only realistic |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 112 | action is to delete the object. |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 113 | \end{methoddesc} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 114 | |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 115 | \begin{seealso} |
Fred Drake | 74810d5 | 1998-04-03 06:49:26 +0000 | [diff] [blame] | 116 | \seemodule{gzip}{reading and writing \program{gzip}-format files} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 117 | \end{seealso} |
Guido van Rossum | 04bc9d6 | 1997-04-30 18:12:27 +0000 | [diff] [blame] | 118 | |
| 119 | |