gpt4 book ai didi

时间:2018-01-08 标签:c++zlib: incorrect header check

转载 作者:行者123 更新时间:2023-11-30 05:45:41 31 4
gpt4 key购买 nike

使用 zlib 版本 1.2.7我遇到了一个奇怪的问题:调用 inflate() 失败并出现错误 -3 Z_DATA_ERROR 和消息“不正确的 header 检查”。在此之前使用 deflate() 压缩数据。这是此错误的简单示例。有什么问题吗?

    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;
}

最佳答案

这看起来像一个错误:

readStream.avail_out = 0;

它应该是:

readStream.avail_out = buffSize;

关于时间:2018-01-08 标签:c++zlib: incorrect header check,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29260784/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com