gpt4 book ai didi

c++ - boost::iostreams::zlib::default_noheader 似乎被忽略了

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:02:11 28 4
gpt4 key购买 nike

我在让 boost::iostreams 的 zlib 过滤器忽略 gzip header 时遇到问题...似乎将 zlib_param 的 default_noheader 设置为 true 然后调用 zlib_decompressor() 会产生“data_error”错误(不正确的 header 检查)。这告诉我 zlib 仍然期望找到标题。有没有人得到 boost::iostreams::zlib 来解压缩没有标题的数据?我需要能够读取和解压缩没有两字节 header 的文件/流。任何帮助将不胜感激。

这是 boost::iostreams::zlib 文档提供的示例程序的修改版本:

#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>

int main(int argc, char** argv)
{
using namespace std;
using namespace boost::iostreams;

ifstream ifs(argv[1]);
ofstream ofs("out");
boost::iostreams::filtering_istreambuf in;
zlib_params p(
zlib::default_compression,
zlib::deflated,
zlib::default_window_bits,
zlib::default_mem_level,
zlib::default_strategy,
true
);

try
{
in.push(zlib_decompressor(p));
in.push(ifs);
boost::iostreams::copy(in, ofs);
ofs.close();
ifs.close();
}
catch(zlib_error& e)
{
cout << "zlib_error num: " << e.error() << endl;
}
return 0;
}

我知道我的测试数据还不错;我写了一个小程序在测试文件上调用 gzread();它已成功解压......所以我很困惑为什么这不起作用。

提前致谢。

-冰

最佳答案

我想你想做的是描述的事情 here这是调整窗口位参数。

例如

zlib_params p;
p.window_bits = 16 + MAX_WBITS;

in.push(zlib_decompressor(p));
in.push(ifs);

MAX_WBITS 我认为是在 zlib.h 中定义的。

关于c++ - boost::iostreams::zlib::default_noheader 似乎被忽略了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3248818/

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