I want to parse a Git packfile in PHP with zlib. (Details on the format here and here). The problem, as mentioned in those articles, is that there's no length specified in the packfile for the compressed data, meaning you have to throw it into zlib and use zlib to figure out where data starts and stops. While zlib's native C API provides the Z_STREAM_END constant which is returned when the end of the compressed data is reached, PHP's zlib extension offers no such option. My only option seems to be to add one byte to the input stream at a time and check whether total_in (part of the zlib stream struct) is 0, which, according to the PHP and zlib source code, is reset to zero whenever inflate() returns Z_STREAM_END. EDIT: PHP resets the total_in value, not zlib. This is changed in the pull request linked in my answer below.
The problem is, how do I get the value of total_in? PHP's inflate_init() function returns a "context resource" which from my perusal of the source code represents the struct zlib uses for decompressing.
Is it possible, in pure PHP, to get the the value of total_in from the internal struct using the context resource?
Thanks.
EDIT: Basically, I want to be able to use stream_context_get_options() on the zlib.inflate context, but I can't because I get Invalid stream/context parameter.