boost::iostreams::zlib::default_noheader 似乎被忽略
我无法让 boost::iostreams 的 zlib 过滤器忽略 gzip 标头...似乎将 zlib_param 的 default_noheader 设置为 true 然后调用 zlib_decompressor() 会产生“data_error”错误(标头检查不正确)。这告诉我 zlib 仍然期望找到标头。 有没有人获得 boost::iostreams::zlib 来解压缩没有标头的数据?我需要能够读取和解压缩没有两字节标头的文件/流。任何帮助将不胜感激。
下面是 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() ;它已成功解压......所以我很困惑为什么这不起作用。
提前致谢。
-冰
I'm having trouble getting boost::iostreams's zlib filter to ignore gzip headers ... It seems that setting zlib_param's default_noheader to true and then calling zlib_decompressor() produces the 'data_error' error (incorrect header check). This tells me zlib is still expecting to find headers.
Has anyone gotten boost::iostreams::zlib to decompress data without headers? I need to be able to read and decompress files/streams that do not have the two-byte header. Any assistance will be greatly appreciated.
Here's a modified version of the sample program provided by the boost::iostreams::zlib documentation:
#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;
}
I know my test data is not bad; I wrote a small program to call gzread() on the test file; it is successfully decompressed ... so I'm confused as to why this does not work.
Thanks in advance.
-Ice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你想做的是这里描述的事情 是调整
window bits
参数。例如
我认为 MAX_WBITS 是在 zlib.h 中定义的。
I think what you want to do is something that's described here which is to adjust the
window bits
parameter.e.g
MAX_WBITS
is defined in zlib.h I think.很简单,试试这个:
Link with zlib and include zlib.h
您可以通过使用 fileno( stdout ) 使用 STDOUT 而不是文件
Much simple, try this:
Link with zlib and include zlib.h
You can use STDOUT instead of a file by using fileno( stdout )
只需使用
boost:: iostreams::gzip_decompressor
用于解压缩 gzip 文件。例如:
Just use the
boost::iostreams::gzip_decompressor
for decompressing gzip files.For example: