You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stream helpers truncate compressed iterators at empty chunks #2252
read_in_chunks and exhaust_iterator stop at the first empty chunk from an iterator, even when more data follows. Empty output is normal for a streaming compressor while it buffers input. Passing that iterator to these helpers truncates the compressed file.
Reproduced on trunk (b2e794d), Python 3.12:
importzlibfromlibcloud.utils.filesimportexhaust_iterator, read_in_chunkscompressor=zlib.compressobj()
chunks= [compressor.compress(row) forrowin (b"first row\n", b"second row\n")]
chunks.append(compressor.flush())
print([len(chunk) forchunkinchunks]) # includes an empty chunkzlib.decompress(exhaust_iterator(iter(chunks)))
# zlib.error: incomplete or truncated streamzlib.decompress(b"".join(read_in_chunks(iter(chunks))))
# same error
Both helpers should consume an iterator until StopIteration. This affects the Backblaze B2 upload paths that use exhaust_iterator, as well as callers using read_in_chunks to prepare a compressed upload.
AI disclosure: Codex reproduced the failure and prepared the fix and tests.
Activity