class bz2.BZ2Decompressor
Create a new decompressor object. This object may be used to decompress data incrementally. For one-shot compression, use the decompress()
function instead.
Note
This class does not transparently handle inputs containing multiple compressed streams, unlike decompress()
and BZ2File
. If you need to decompress a multi-stream input with BZ2Decompressor
, you must use a new decompressor for each stream.
-
decompress(data, max_length=-1)
-
Decompress data (a bytes-like object), returning uncompressed data as bytes. Some of data may be buffered internally, for use in later calls to
decompress()
. The returned data should be concatenated with the output of any previous calls todecompress()
.If max_length is nonnegative, returns at most max_length bytes of decompressed data. If this limit is reached and further output can be produced, the
needs_input
attribute will be set toFalse
. In this case, the next call todecompress()
may provide data asb''
to obtain more of the output.If all of the input data was decompressed and returned (either because this was less than max_length bytes, or because max_length was negative), the
needs_input
attribute will be set toTrue
.Attempting to decompress data after the end of stream is reached raises an EOFError. Any data found after the end of the stream is ignored and saved in the
unused_data
attribute.Changed in version 3.5: Added the max_length parameter.
-
eof
-
True
if the end-of-stream marker has been reached.New in version 3.3.
-
unused_data
-
Data found after the end of the compressed stream.
If this attribute is accessed before the end of the stream has been reached, its value will be
b''
.
-
needs_input
-
False
if thedecompress()
method can provide more decompressed data before requiring new uncompressed input.New in version 3.5.
Please login to continue.