When reading a stream of bytes that contains a Deflate stream, is it possible to detect where the Delfate stream ends? If so: how? (Ideally in Python).
I see Decompress.unused_data, that looks like it could be involved, but I'm not quite sure how to use it.
Context: writing a streaming unZIP implementation where the compressed data size, i.e. the size of the Deflate stream of each compressed file is not always known up-front.
The only way to do it is to decode the entire deflate stream. The deflate format is self-terminating, so it tells you when it ends. There is no magic sequence of bits or bytes that you can search for to find the end.
Indeed, in Python you would use decompressobj
in the zlib module to do this, checking unused_data
until it is non-empty. When it is, the deflate stream terminated at the byte before what was returned by unused_data
.