I'm using the idea of the gzip code posted in zlib.
For initialization I use deflateInit2(p_strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY)
.
I'm zipping a stream. Each packet with Z_FULL_FLUSH
, except from the last which I use Z_FINISH
.
After zipping each packet, I'm reordering the packets.
data in packets ---> [zip] ---> [reordering] ---> ...
If I inflate the data after the zip, I'm getting the exact file before zipping.
If I inflate the data after the reordering of the packets (again: each packet is deflated with Z_FULL_FLUSH
, except for the last Z_FINISH
) I get a file that is very similar to the original file before zipping. The difference is in the end of the file: it lack of bytes. That's because when I'm inflating it, I get an error for the last packet (Z_DATA_ERROR
). If I inflate, let's say, with chunks of 50KB, the inflated file after reordering is the same file as the input, less <50KB (the whole last packet is gone cause of the error). If I decrease the inflating chunk size to 8B, I still get the Z_DATA_ERROR
, but now I loose less data while inflating, (In my example I lack one Byte from the original file).
I'm not reordering the last packet (Z_FINISH
).
I tried to send all of the packets with Z_FULL_FLUSH
and then, send another "empty" packet (only Z_FINISH
which is 10 bytes).
Why is this happening? If I use Z_FULL_FLUSH, Why can't the inflater inflate it correctly? does it remember the order of the deflated packets?
Any information will help, Thanks.