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