rest25/library/zlib.rst => rest262/library/zlib.rst
4
5.. module:: zlib
6   :synopsis: Low-level interface to compression and decompression routines compatible with
7              gzip.
8
9
10For applications that require data compression, the functions in this module
11allow compression and decompression, using the zlib library. The zlib library
n12-has its own home page at `<http://www.zlib.net>`_.   There are known
n12+has its own home page at http://www.zlib.net.   There are known
13incompatibilities between the Python module and versions of the zlib library
14earlier than 1.1.3; 1.1.3 has a security vulnerability, so we recommend using
151.1.4 or later.
16
17zlib's functions have many options and often need to be used in a particular
18order.  This documentation doesn't attempt to cover all of the permutations;
n19-consult the zlib manual at `<http://www.zlib.net/manual.html>`_ for
n19+consult the zlib manual at http://www.zlib.net/manual.html for authoritative
20-authoritative information.
20+information.
21+ 
22+For reading and writing ``.gz`` files see the :mod:`gzip` module. For
23+other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
24+:mod:`tarfile` modules.
21
22The available exception and functions in this module are:
23
24
25.. exception:: error
26
27   Exception raised on compression and decompression errors.
28
29
n30-.. function:: adler32(string[, value])
n34+.. function:: adler32(data[, value])
31
n32-   Computes a Adler-32 checksum of *string*.  (An Adler-32 checksum is almost as
n36+   Computes a Adler-32 checksum of *data*.  (An Adler-32 checksum is almost as
33   reliable as a CRC32 but can be computed much more quickly.)  If *value* is
34   present, it is used as the starting value of the checksum; otherwise, a fixed
35   default value is used.  This allows computing a running checksum over the
n36-   concatenation of several input strings.  The algorithm is not cryptographically
n40+   concatenation of several inputs.  The algorithm is not cryptographically
37   strong, and should not be used for authentication or digital signatures.  Since
38   the algorithm is designed for use as a checksum algorithm, it is not suitable
39   for use as a general hash algorithm.
n44+ 
45+   This function always returns an integer object.
46+ 
47+.. note::
48+   To generate the same numeric value across all Python versions and
49+   platforms use adler32(data) & 0xffffffff.  If you are only using
50+   the checksum in packed binary format this is not necessary as the
51+   return value is the correct 32bit binary representation
52+   regardless of sign.
53+ 
54+.. versionchanged:: 2.6
55+   The return value is in the range [-2**31, 2**31-1]
56+   regardless of platform.  In older versions the value is
57+   signed on some platforms and unsigned on others.
58+ 
59+.. versionchanged:: 3.0
60+   The return value is unsigned and in the range [0, 2**32-1]
61+   regardless of platform.
40
41
42.. function:: compress(string[, level])
43
44   Compresses the data in *string*, returning a string contained compressed data.
45   *level* is an integer from ``1`` to ``9`` controlling the level of compression;
46   ``1`` is fastest and produces the least compression, ``9`` is slowest and
47   produces the most.  The default value is ``6``.  Raises the :exc:`error`
51.. function:: compressobj([level])
52
53   Returns a compression object, to be used for compressing data streams that won't
54   fit into memory at once.  *level* is an integer from ``1`` to ``9`` controlling
55   the level of compression; ``1`` is fastest and produces the least compression,
56   ``9`` is slowest and produces the most.  The default value is ``6``.
57
58
n59-.. function:: crc32(string[, value])
n81+.. function:: crc32(data[, value])
60
61   .. index::
62      single: Cyclic Redundancy Check
63      single: checksum; Cyclic Redundancy Check
64
n65-   Computes a CRC (Cyclic Redundancy Check)  checksum of *string*. If *value* is
n87+   Computes a CRC (Cyclic Redundancy Check)  checksum of *data*. If *value* is
66   present, it is used as the starting value of the checksum; otherwise, a fixed
67   default value is used.  This allows computing a running checksum over the
n68-   concatenation of several input strings.  The algorithm is not cryptographically
n90+   concatenation of several inputs.  The algorithm is not cryptographically
69   strong, and should not be used for authentication or digital signatures.  Since
70   the algorithm is designed for use as a checksum algorithm, it is not suitable
71   for use as a general hash algorithm.
72
n73-   .. % 
n95+   This function always returns an integer object.
96+ 
97+.. note::
98+   To generate the same numeric value across all Python versions and
99+   platforms use crc32(data) & 0xffffffff.  If you are only using
100+   the checksum in packed binary format this is not necessary as the
101+   return value is the correct 32bit binary representation
102+   regardless of sign.
103+ 
104+.. versionchanged:: 2.6
105+   The return value is in the range [-2**31, 2**31-1]
106+   regardless of platform.  In older versions the value would be
107+   signed on some platforms and unsigned on others.
108+ 
109+.. versionchanged:: 3.0
110+   The return value is unsigned and in the range [0, 2**32-1]
111+   regardless of platform.
74
75
76.. function:: decompress(string[, wbits[, bufsize]])
77
78   Decompresses the data in *string*, returning a string containing the
79   uncompressed data.  The *wbits* parameter controls the size of the window
80   buffer.  If *bufsize* is given, it is used as the initial size of the output
81   buffer.  Raises the :exc:`error` exception if any error occurs.
130   Returns a copy of the compression object.  This can be used to efficiently
131   compress a set of data that share a common initial prefix.
132
133   .. versionadded:: 2.5
134
135Decompression objects support the following methods, and two attributes:
136
137
n138-.. attribute:: XXX Class.unused_data
n176+.. attribute:: Decompress.unused_data
139
140   A string which contains any bytes past the end of the compressed data. That is,
141   this remains ``""`` until the last byte that contains compression data is
142   available.  If the whole string turned out to contain compressed data, this is
143   ``""``, the empty string.
144
145   The only way to determine where a string of compressed data ends is by actually
146   decompressing it.  This means that when compressed data is contained part of a
147   larger file, you can only find the end of it by reading data and feeding it
148   followed by some non-empty string into a decompression object's
149   :meth:`decompress` method until the :attr:`unused_data` attribute is no longer
150   the empty string.
151
152
t153-.. attribute:: XXX Class.unconsumed_tail
t191+.. attribute:: Decompress.unconsumed_tail
154
155   A string that contains any data that was not consumed by the last
156   :meth:`decompress` call because it exceeded the limit for the uncompressed data
157   buffer.  This data has not yet been seen by the zlib machinery, so you must feed
158   it (possibly with further data concatenated to it) back to a subsequent
159   :meth:`decompress` method call in order to get correct output.
160
161
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op