I am using zlib to inflate some deflate compressed data. The caller specifies how many uncompressed bytes it wants, through zstream avail_out. What I need to get is how many actual bytes were consumed from the next_in buffer to inflate the requested avail_out number of bytes. The total_in amount is how much was inflated but it is larger than what was actually "needed" to populate the next_out buffer.
Example:
I have 126 bytes of compressed data and want to get the first 4 bytes of the uncompressed data. Now I want to pick up and get the next 4 bytes of uncompressed data, so
Where do I set the next_in pointer after the first inflate to start in the compressed data, so that after inflation the fext 4 bytes are what I want, as if I originally set avail_out as 8 and not 4?
I've tried Z_BLOCK to get the unused bits from the last byte but they don't align where I'd expect the next_in read to start.
Any ideas how to set next_in to inflate where I'd expect the next 4 uncompressed bytes to be? The stream is torn down between these calls.
Update:
I'm trying to do this something like this statement from the zlib how to site:
For applications where zlib streams are embedded in other data, this routine would need to be modified to return the unused data, or at least indicate how much of the input data was not used, so the application would know where to pick up after the zlib stream.
Clarification:
A better question might be:
Is it possible to know where in the compressed data equates to the 4 uncompressed bytes I wanted read? Is there something within zstream/zlib that stores/reports this?