Issue 853061: Inconsistent behavior of compressing the BZip2 format (original) (raw)

There are three ways to compress data in bz2 but they don't handle an empty string same way. BZ2File and compress can accept an empty string but BZ2Compressor raises ValueError.

import bz2 bz2f = bz2.BZ2File('test', 'w') bz2f.write('') bz2f.close() bz2.compress('') 'BZh9\x17rE8P\x90\x00\x00\x00\x00' bz2c = bz2.BZ2Compressor() bz2c.compress('') Traceback (most recent call last): File "", line 1, in ? ValueError: the bz2 library has received wrong parameters