self.assertTrue(lzd.eof)
self.assertEqual(lzd.unused_data, b"")
+ def test_decompressor_chunks_empty(self):
+ lzd = LZMADecompressor()
+ out = []
+ for i in range(0, len(COMPRESSED_XZ), 10):
+ self.assertFalse(lzd.eof)
+ out.append(lzd.decompress(b''))
+ out.append(lzd.decompress(b''))
+ out.append(lzd.decompress(b''))
+ out.append(lzd.decompress(COMPRESSED_XZ[i:i+10]))
+ out = b"".join(out)
+ self.assertEqual(out, INPUT)
+ self.assertEqual(lzd.check, lzma.CHECK_CRC64)
+ self.assertTrue(lzd.eof)
+ self.assertEqual(lzd.unused_data, b"")
+
def test_decompressor_chunks_maxsize(self):
lzd = LZMADecompressor()
max_length = 100
lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
self._test_decompressor(lzd, cdata, lzma.CHECK_NONE)
+ def test_roundtrip_raw_empty(self):
+ lzc = LZMACompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
+ cdata = lzc.compress(INPUT)
+ cdata += lzc.compress(b'')
+ cdata += lzc.compress(b'')
+ cdata += lzc.compress(b'')
+ cdata += lzc.flush()
+ lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
+ self._test_decompressor(lzd, cdata, lzma.CHECK_NONE)
+
def test_roundtrip_chunks(self):
lzc = LZMACompressor()
cdata = []
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
+ def test_roundtrip_empty_chunks(self):
+ lzc = LZMACompressor()
+ cdata = []
+ for i in range(0, len(INPUT), 10):
+ cdata.append(lzc.compress(INPUT[i:i+10]))
+ cdata.append(lzc.compress(b''))
+ cdata.append(lzc.compress(b''))
+ cdata.append(lzc.compress(b''))
+ cdata.append(lzc.flush())
+ cdata = b"".join(cdata)
+ lzd = LZMADecompressor()
+ self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
+
# LZMADecompressor intentionally does not handle concatenated streams.
def test_decompressor_multistream(self):
Py_BEGIN_ALLOW_THREADS
lzret = lzma_code(&c->lzs, action);
data_size = (char *)c->lzs.next_out - PyBytes_AS_STRING(result);
+ if (lzret == LZMA_BUF_ERROR && len == 0 && c->lzs.avail_out > 0)
+ lzret = LZMA_OK; /* That wasn't a real error */
Py_END_ALLOW_THREADS
if (catch_lzma_error(lzret))
goto error;
PyObject *result;
lzma_stream *lzs = &d->lzs;
+ if (lzs->avail_in == 0)
+ return PyBytes_FromStringAndSize(NULL, 0);
+
if (max_length < 0 || max_length >= INITIAL_BUFFER_SIZE)
result = PyBytes_FromStringAndSize(NULL, INITIAL_BUFFER_SIZE);
else