Использование zlib версии 1.2.7 У меня возникла странная проблема: вызов функции inflate() с ошибкой -3 Z_DATA_ERROR и сообщение «неправильная проверка заголовка». Данные были сжаты с помощью deflate() до этого. Вот простой пример этой ошибки. Что с этим не так?C++ zlib: неверная проверка заголовка
std::string testWord = "Hello world";
const int buffSize = 1000;
byte buffer[buffSize];
byte outBuffer[buffSize];
z_stream readStream, writeStream;
readStream.zalloc = Z_NULL;
readStream.zfree = Z_NULL;
readStream.opaque = Z_NULL;
readStream.avail_in = 0;
readStream.next_in = Z_NULL;
writeStream.zalloc = Z_NULL;
writeStream.zfree = Z_NULL;
writeStream.opaque = Z_NULL;
writeStream.avail_in = 0;
writeStream.next_in = Z_NULL;
int rez = inflateInit(&readStream);
if (rez != Z_OK)
std::cout << "InflateInit returned error " << rez;
rez = deflateInit(&writeStream, Z_DEFAULT_COMPRESSION);
if (rez != Z_OK)
std::cout << "deflateInit returned error " << rez;
writeStream.next_in = (byte*)testWord.c_str();
writeStream.avail_in = testWord.size();
writeStream.next_out = (Bytef*) buffer;
writeStream.avail_out = buffSize;
rez = deflate(&writeStream, Z_FINISH);
if (rez != Z_STREAM_END)
std::cout << "deflate returned error " << rez;
rez = deflateEnd(&writeStream);
if (rez != Z_OK)
std::cout << "deflateEnd returned error " << rez;
readStream.next_in = buffer;
readStream.avail_in = buffSize - writeStream.avail_out;
readStream.next_out = outBuffer;
readStream.avail_out = buffSize;
rez = inflate(&readStream, Z_FINISH);
if (rez != Z_STREAM_END)
{
std::cout << "inflate returned error " << rez << " msg: " << readStream.msg;
return;
}
Да, был ошибкой, thx. Я исправил его, но основная проблема не решена. – Andrey