~ubuntu-branches/ubuntu/natty/python3.2/natty-security

« back to all changes in this revision

Viewing changes to Doc/library/zlib.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-01-16 18:09:56 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110116180956-yf91p6ode1z6lsi1
Tags: 3.2~rc1-0ubuntu1
Python 3.2 release candidate 1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
   regardless of sign.
52
52
 
53
53
 
54
 
.. function:: compress(string[, level])
 
54
.. function:: compress(data[, level])
55
55
 
56
 
   Compresses the data in *string*, returning a string contained compressed data.
 
56
   Compresses the bytes in *data*, returning a bytes object containing compressed data.
57
57
   *level* is an integer from ``1`` to ``9`` controlling the level of compression;
58
58
   ``1`` is fastest and produces the least compression, ``9`` is slowest and
59
59
   produces the most.  The default value is ``6``.  Raises the :exc:`error`
92
92
   regardless of sign.
93
93
 
94
94
 
95
 
.. function:: decompress(string[, wbits[, bufsize]])
 
95
.. function:: decompress(data[, wbits[, bufsize]])
96
96
 
97
 
   Decompresses the data in *string*, returning a string containing the
 
97
   Decompresses the bytes in *data*, returning a bytes object containing the
98
98
   uncompressed data.  The *wbits* parameter controls the size of the window
99
99
   buffer, and is discussed further below.
100
100
   If *bufsize* is given, it is used as the initial size of the output
125
125
Compression objects support the following methods:
126
126
 
127
127
 
128
 
.. method:: Compress.compress(string)
 
128
.. method:: Compress.compress(data)
129
129
 
130
 
   Compress *string*, returning a string containing compressed data for at least
131
 
   part of the data in *string*.  This data should be concatenated to the output
 
130
   Compress *data*, returning a bytes object containing compressed data for at least
 
131
   part of the data in *data*.  This data should be concatenated to the output
132
132
   produced by any preceding calls to the :meth:`compress` method.  Some input may
133
133
   be kept in internal buffers for later processing.
134
134
 
135
135
 
136
136
.. method:: Compress.flush([mode])
137
137
 
138
 
   All pending input is processed, and a string containing the remaining compressed
 
138
   All pending input is processed, and a bytes object containing the remaining compressed
139
139
   output is returned.  *mode* can be selected from the constants
140
140
   :const:`Z_SYNC_FLUSH`,  :const:`Z_FULL_FLUSH`,  or  :const:`Z_FINISH`,
141
141
   defaulting to :const:`Z_FINISH`.  :const:`Z_SYNC_FLUSH` and
142
 
   :const:`Z_FULL_FLUSH` allow compressing further strings of data, while
 
142
   :const:`Z_FULL_FLUSH` allow compressing further bytestrings of data, while
143
143
   :const:`Z_FINISH` finishes the compressed stream and  prevents compressing any
144
144
   more data.  After calling :meth:`flush` with *mode* set to :const:`Z_FINISH`,
145
145
   the :meth:`compress` method cannot be called again; the only realistic action is
157
157
 
158
158
.. attribute:: Decompress.unused_data
159
159
 
160
 
   A string which contains any bytes past the end of the compressed data. That is,
 
160
   A bytes object which contains any bytes past the end of the compressed data. That is,
161
161
   this remains ``""`` until the last byte that contains compression data is
162
 
   available.  If the whole string turned out to contain compressed data, this is
163
 
   ``""``, the empty string.
 
162
   available.  If the whole bytestring turned out to contain compressed data, this is
 
163
   ``b""``, an empty bytes object.
164
164
 
165
 
   The only way to determine where a string of compressed data ends is by actually
 
165
   The only way to determine where a bytestring of compressed data ends is by actually
166
166
   decompressing it.  This means that when compressed data is contained part of a
167
167
   larger file, you can only find the end of it by reading data and feeding it
168
 
   followed by some non-empty string into a decompression object's
 
168
   followed by some non-empty bytestring into a decompression object's
169
169
   :meth:`decompress` method until the :attr:`unused_data` attribute is no longer
170
 
   the empty string.
 
170
   empty.
171
171
 
172
172
 
173
173
.. attribute:: Decompress.unconsumed_tail
174
174
 
175
 
   A string that contains any data that was not consumed by the last
 
175
   A bytes object that contains any data that was not consumed by the last
176
176
   :meth:`decompress` call because it exceeded the limit for the uncompressed data
177
177
   buffer.  This data has not yet been seen by the zlib machinery, so you must feed
178
178
   it (possibly with further data concatenated to it) back to a subsequent
179
179
   :meth:`decompress` method call in order to get correct output.
180
180
 
181
181
 
182
 
.. method:: Decompress.decompress(string[, max_length])
 
182
.. method:: Decompress.decompress(data[, max_length])
183
183
 
184
 
   Decompress *string*, returning a string containing the uncompressed data
 
184
   Decompress *data*, returning a bytes object containing the uncompressed data
185
185
   corresponding to at least part of the data in *string*.  This data should be
186
186
   concatenated to the output produced by any preceding calls to the
187
187
   :meth:`decompress` method.  Some of the input data may be preserved in internal
190
190
   If the optional parameter *max_length* is supplied then the return value will be
191
191
   no longer than *max_length*. This may mean that not all of the compressed input
192
192
   can be processed; and unconsumed data will be stored in the attribute
193
 
   :attr:`unconsumed_tail`. This string must be passed to a subsequent call to
 
193
   :attr:`unconsumed_tail`. This bytestring must be passed to a subsequent call to
194
194
   :meth:`decompress` if decompression is to continue.  If *max_length* is not
195
 
   supplied then the whole input is decompressed, and :attr:`unconsumed_tail` is an
196
 
   empty string.
 
195
   supplied then the whole input is decompressed, and :attr:`unconsumed_tail` is
 
196
   empty.
197
197
 
198
198
 
199
199
.. method:: Decompress.flush([length])
200
200
 
201
 
   All pending input is processed, and a string containing the remaining
 
201
   All pending input is processed, and a bytes object containing the remaining
202
202
   uncompressed output is returned.  After calling :meth:`flush`, the
203
203
   :meth:`decompress` method cannot be called again; the only realistic action is
204
204
   to delete the object.