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