Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 200e00a

Browse files
committed
Update bz2 docs following issue #1625.
1 parent 55b4338 commit 200e00a

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

Doc/library/bz2.rst

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ All of the classes in this module may safely be accessed from multiple threads.
3737
*fileobj*), or operate directly on a named file (named by *filename*).
3838
Exactly one of these two parameters should be provided.
3939

40-
The *mode* argument can be either ``'r'`` for reading (default), or ``'w'``
41-
for writing.
40+
The *mode* argument can be either ``'r'`` for reading (default), ``'w'`` for
41+
overwriting, or ``'a'`` for appending. If *fileobj* is provided, a mode of
42+
``'w'`` does not truncate the file, and is instead equivalent to ``'a'``.
4243

4344
The *buffering* argument is ignored. Its use is deprecated.
4445

45-
If *mode* is ``'w'``, *compresslevel* can be a number between ``1`` and
46-
``9`` specifying the level of compression: ``1`` produces the least
47-
compression, and ``9`` (default) produces the most compression.
46+
If *mode* is ``'w'`` or ``'a'``, *compresslevel* can be a number between
47+
``1`` and ``9`` specifying the level of compression: ``1`` produces the
48+
least compression, and ``9`` (default) produces the most compression.
49+
50+
If *mode* is ``'r'``, the input file may be the concatenation of multiple
51+
compressed streams.
4852

4953
:class:`BZ2File` provides all of the members specified by the
5054
:class:`io.BufferedIOBase`, except for :meth:`detach` and :meth:`truncate`.
@@ -70,6 +74,10 @@ All of the classes in this module may safely be accessed from multiple threads.
7074
.. versionchanged:: 3.3
7175
The *fileobj* argument to the constructor was added.
7276

77+
.. versionchanged:: 3.3
78+
The ``'a'`` (append) mode was added, along with support for reading
79+
multi-stream files.
80+
7381

7482
Incremental (de)compression
7583
---------------------------
@@ -106,14 +114,20 @@ Incremental (de)compression
106114
incrementally. For one-shot compression, use the :func:`decompress` function
107115
instead.
108116

117+
.. note::
118+
This class does not transparently handle inputs containing multiple
119+
compressed streams, unlike :func:`decompress` and :class:`BZ2File`. If
120+
you need to decompress a multi-stream input with :class:`BZ2Decompressor`,
121+
you must use a new decompressor for each stream.
122+
109123
.. method:: decompress(data)
110124

111125
Provide data to the decompressor object. Returns a chunk of decompressed
112126
data if possible, or an empty byte string otherwise.
113127

114-
Attempting to decompress data after the end of stream is reached raises
115-
an :exc:`EOFError`. If any data is found after the end of the stream, it
116-
is ignored and saved in the :attr:`unused_data` attribute.
128+
Attempting to decompress data after the end of the current stream is
129+
reached raises an :exc:`EOFError`. If any data is found after the end of
130+
the stream, it is ignored and saved in the :attr:`unused_data` attribute.
117131

118132

119133
.. attribute:: eof
@@ -127,6 +141,9 @@ Incremental (de)compression
127141

128142
Data found after the end of the compressed stream.
129143

144+
If this attribute is accessed before the end of the stream has been
145+
reached, its value will be ``b''``.
146+
130147

131148
One-shot (de)compression
132149
------------------------
@@ -145,5 +162,11 @@ One-shot (de)compression
145162

146163
Decompress *data*.
147164

165+
If *data* is the concatenation of multiple compressed streams, decompress
166+
all of the streams.
167+
148168
For incremental decompression, use a :class:`BZ2Decompressor` instead.
149169

170+
.. versionchanged:: 3.3
171+
Support for multi-stream inputs was added.
172+

0 commit comments

Comments
 (0)