C++ boost::iostreams::zlib::默认\u noheader似乎被忽略

C++ boost::iostreams::zlib::默认\u noheader似乎被忽略,c++,zlib,decoding,boost-iostreams,text-decoding,C++,Zlib,Decoding,Boost Iostreams,Text Decoding,我很难让boost::iostreams的zlib筛选器忽略gzip头。。。似乎将zlib_param的default_noheader设置为true,然后调用zlib_decompressor()会产生“data_error”错误(不正确的头检查)。这告诉我zlib仍然希望找到标题。 有没有人让boost::iostreams::zlib解压没有标题的数据?我需要能够读取和解压缩没有双字节头的文件/流。任何帮助都将不胜感激 以下是boost::iostreams::zlib文档提供的示例程序的

我很难让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;
}
#包括
#包括
#包括
#包括
#包括
int main(int argc,字符**argv)
{
使用名称空间std;
使用名称空间boost::iostreams;
ifs流ifs(argv[1]);
流of s(“out”);
boost::iostreams::filtering_istreambuf in;
zlib_参数p(
zlib::默认_压缩,
zlib::通缩,
zlib::默认窗口位,
zlib::默认的内存级别,
zlib::默认_策略,
真的
);
尝试
{
in.push(zlib_减压器(p));
in.push(ifs);
boost::iostreams::copy(in,ofs);
ofs.close();
ifs.close();
}
捕获(zlib_错误和e)
{

cout我认为您要做的是上面描述的事情,即调整
窗口位
参数

e、 g

MAX\u WBITS
是在zlib.h中定义的。我想。

非常简单,试试这个:

FILE* fp = fopen("abc.gz", "w+");
int dupfd = dup( fileno( fp ) );
int zfp = gzdopen( dupfd, "ab" )
gzwrite( zfp, YOUR_DATA, YOUR_DATA_LEN );
gzclose( zfp );
fclose( fp );
与zlib链接并包含zlib.h 通过使用fileno(STDOUT),您可以使用STDOUT而不是文件。

只需使用来解压缩gzip文件

例如:

#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>

// ...

boost::iostreams::filtering_istream stream;
stream.push(boost::iostreams::gzip_decompressor());
ifstream file(filename, std::ios_base::in | std::ios_base::binary);
stream.push(file);
#包括
#包括
#包括
// ...
boost::iostreams::过滤流;
push(boost::iostreams::gzip_decompressor());
ifstream文件(文件名,std::ios_base::in | std::ios_base::binary);
stream.push(文件);
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>

// ...

boost::iostreams::filtering_istream stream;
stream.push(boost::iostreams::gzip_decompressor());
ifstream file(filename, std::ios_base::in | std::ios_base::binary);
stream.push(file);