ZLib Inflate () nie działa z -3 Z_DATA_ERROR

Próbuję rozpakować plik, wywołując funkcję inflate, ale zawsze kończy się ona niepowodzeniem z Z_DATA_ERROR, nawet gdy używam przykładowego programu ze strony internetowej. Myślę, że może plik zip, który mam, nie jest obsługiwany. Załączam zdjęcie nagłówka zip poniżej.

A oto funkcja, którą napisałem, aby wykonać rozpakowywanie. Odczytałem cały plik na raz (około 34 KB) i przekazałem go do tej funkcji. Uwaga: Próbowałem przekazać cały plik zip z nagłówkiem zip, jak również przeskoczyć nagłówek pliku zip i tylko przekazując spakowane dane zawiodły z Z_DATA_ERROR, gdy wywołano inflate ().

int CHttpDownloader::unzip(unsigned char * pDest, unsigned long * ulDestLen, unsigned char *  pSource, int iSourceLen)
{
int ret = 0;
unsigned int uiUncompressedBytes = 0; // Number of uncompressed bytes returned from inflate() function
unsigned char * pPositionDestBuffer = pDest; // Current position in dest buffer
unsigned char * pLastSource = &pSource[iSourceLen]; // Last position in source buffer
z_stream strm;

// Skip over local file header
SLocalFileHeader * header = (SLocalFileHeader *) pSource;
pSource += sizeof(SLocalFileHeader) + header->sFileNameLen + header->sExtraFieldLen;


// We should now be at the beginning of the stream data
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit2(&strm, 16+MAX_WBITS);
if (ret != Z_OK)
{
return -1;
}

// Uncompress the data
strm.avail_in = header->iCompressedSize; //iSourceLen;
strm.next_in = pSource;

do {
strm.avail_out = *ulDestLen;
strm.next_out = pPositionDestBuffer;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR;     /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return -2;
}
uiUncompressedBytes = *ulDestLen - strm.avail_out;
*ulDestLen -= uiUncompressedBytes; // ulDestSize holds number of free/empty bytes in buffer
pPositionDestBuffer += uiUncompressedBytes;
} while (strm.avail_out == 0);

// Close the decompression stream
inflateEnd(&strm);
ASSERT(ret == Z_STREAM_END);

return 0;
}

Więc moje pytanie brzmi, czy typ pliku zip, który czytam, nie jest obsługiwany przez funkcję inflate () ZLib? Czy jest coś nie tak z moją funkcją CHttpDownloader :: unzip ()? Dzięki za pomoc :)

questionAnswers(2)

yourAnswerToTheQuestion