Decompressing GZIP with zlib (via GZIPDecompressorInputStream)


#1

Hi Jules,

We've been working with GZIPDecompressorInputStream today and found that it doesn't have the option to set up zlib to decompress gzip formats (only deflate or zlib decompression).

In the contructor of GZIPDecompressHelper it has the line...

streamIsValid = (inflateInit2 (&stream, dontWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);

So this sets the flag to be -MAX_WBITS or MAX_WBITS depending on dontWrap.

However, this post on stackoverflow lists a 3rd option for gzip formatted files:

But zlib can decompress all those formats:

to (de-)compress deflate format, use wbits = -zlib.MAX_WBITS
to (de-)compress zlib format, use wbits = zlib.MAX_WBITS
to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16

So, if we needed to decompress in gzip format, at present we have to go and change the value passed to 
inflateInit2() inside the GZIPDecompressHelper class to MAX_WBITS | 16 . Perhaps it could be changed so that there is some kind of flag we can pass in the constructor?

I'm sure there is an equivalent change for encoding too.

Also, according to the same post, apparently you can add 32 to MAX_WBITS to enable zlib and gzip decoding with automatic header detection...

Cheers!

Adam


#2

Hi Adam - good request! I've added an enum for this now - let me know if it works for you!


#3

Yeah, that seems to do the trick! Thanks!! :)