Thanks Brion & Peter,
Brion:
And the real hard one to figure out: PHP's gzdeflate(), gzinflate() set the window size to -MAX_WSIZE which disables the checksum. Unless you pass the same parameter to inflateInit(), the perl-side functions will expect those extra bytes and fail without explanation.
I might have searched for this for eons. I never sought of looking up PHP spec, since I have never touched PHP.
------------- Peter: your version dies on file 59, no more data is read, and should not be:
Changing while(read(FH,$in,4096)) { to while($bytesread=read(FH,$in,4096)) { reveals the first chunk read was well below 4096 in these occasions.
-------------
Z_OK vs Z_STREAM_END
From http://www.cpan.org/modules/by-module/Compress/Compress-Zlib-1.03.readme
=> Normally the inflate method consumes I<all> of the input buffer before returning. The exception to this is when inflate detects the end of the stream (Z_STREAM_END). In this case the input buffer >need not< be completely consumed. To allow processing of file formats that embed a deflation stream (e.g. zip, gzip), the inflate method now sets the buffer parameter to be what remains after inflation.
When the return status is Z_STREAM_END, it will be what remains of the buffer (if any) after deflation. When the status is Z_OK it will be an empty string. <=
I found that the input buffer was empty after each inflate(). So both return values are more or less equal in this case. I also found some code eamples that treat them alike.
So I think this problem is resolved.
Thanks again.
Erik Zachte
wikitech-l@lists.wikimedia.org