我正在嘗試使用zlib的充值來解壓我從http數據包收到的一些數據。Zlib從http數據包充值數據
分組如下:
包,本身說,它是用gzip編碼的,所以我覺得它應該工作。但是,當我通過膨脹函數運行數據時,我得到「無效塊類型」。爲了清楚起見,我只將數據包的突出部分傳遞給膨脹函數。我錯過了什麼?
這裏是我使用解壓縮數據的代碼:
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;
}
根據[這篇文章](http://stackoverflow.com/questions/17872152/decompress-with-gz-functions-succeeded-but-failed-with-inflate-functions-using?rq=1)和[這個帖子](http://stackoverflow.com/questions/1838699/how-can-i-decompress-a-gzip-stream-with-zlib?lq=1),我應該使用:'inflateInit2(&strm,16 + MAX_WBITS);'但即使我這樣做,我也會得到「未知的標題標誌集」。 – Drexlin