[Tutor] Python bz2 "IOError: invalid data stream" when trying to decompress

eryksun eryksun at gmail.com
Thu Apr 11 04:16:48 CEST 2013


On Wed, Apr 10, 2013 at 8:18 PM, Rodney Lewis
<therealdotcomboy at gmail.com> wrote:
> My question is at StackOverflow so I won't repeat it here.

Short link:
http://stackoverflow.com/q/15938629/205580

Your function worked fine for me on Windows Python 2.7.3,
compressing/decompressing a text file that's about 150 KiB.

The bz2 module raises IOError("invalid data stream") for the error
codes BZ_DATA_ERROR and BZ_DATA_ERROR_MAGIC:

http://hg.python.org/cpython/file/70274d53c1dd/Modules/bz2module.c#l192

According to the bzip2 docs, BZ_DATA_ERROR is raised when the computed
CRC fails to match the stored CRC, or there's some other anomaly in
the data. BZ_DATA_ERROR_MAGIC means the compressed data didn't start
with the 'BZh' magic bytes.

http://www.bzip.org/1.0.5/bzip2-manual-1.0.5.html#err-handling


More information about the Tutor mailing list