I'm trying to use zlib's inflate to decompress some data I received from an http packet.
The packet is as follows:
The packet, itself, says that it's encoded with gzip, so I think it should work. However, when I run the data through the inflate function, I get "invalid block type". To be clear, I'm only passing in the highlighted portion of the packet to the inflate function. What am I missing?
Here is the code I'm using to decompress the data:
int Decompress(const u_char* strStreamIn, int nStreamInLen, u_char* strStreamOut)
{
int ret = -1;
int err = -1;
z_stream strm = {0};
strm.total_in = strm.avail_in = nStreamInLen;
strm.total_out = strm.avail_out = nStreamInLen * 6;
strm.next_in = (Bytef*) strStreamIn;
strm.next_out = (Bytef*) strStreamOut;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
err = inflateInit2(&strm, -MAX_WBITS);
if (err == Z_OK) {
err = inflate(&strm, Z_FINISH);
if (err == Z_STREAM_END) {
ret = strm.total_out;
}
else {
inflateEnd(&strm);
return err;
}
}
else {
inflateEnd(&strm);
return err;
}
inflateEnd(&strm);
return ret;
}