我认为你需要编写你自己的过滤器。例如,要仔细阅读说明书是.tar.gz和输出文件,我写了类似
//using namespace std;
namespace io = boost::iostreams;
struct tar_expander
{
tar_expander() : out(0), status(header)
{
}
~tar_expander()
{
delete out;
}
/* qualify filter */
typedef char char_type;
struct category :
io::input_filter_tag,
io::multichar_tag
{ };
template<typename Source>
void fetch_n(Source& src, std::streamsize n = block_size)
{
/* my utility */
....
}
// Read up to n filtered characters into the buffer s,
// returning the number of characters read or -1 for EOF.
// Use src to access the unfiltered character sequence
template<typename Source>
std::streamsize read(Source& src, char* s, std::streamsize n)
{
fetch_n(src);
const tar_header &h = cast_buf<tar_header>();
int r;
if (status == header)
{
...
}
std::ofstream *out;
size_t fsize, stored;
static const size_t block_size = 512;
std::vector<char> buf;
enum { header, store_file, archive_end } status;
}
}
我的功能read(Source &...)
时调用接收解压缩后的文本。 使用的过滤器:
ifstream file("/home/..../resample-1.8.1.tar.gz", ios_base::in | ios_base::binary);
io::filtering_streambuf<io::input> in;
in.push(tar_expander());
in.push(io::gzip_decompressor());
in.push(file);
io::copy(in, cout);
会做的操作,如调用'函数getline()''然后压缩()'它通过你的循环工作? – user99545 2012-02-28 20:28:50
@ user99545:否:因为X根据二进制数据创建自己。 – ATemp 2012-02-28 20:30:47
我不明白为什么不。我已经使用boost iostreams以这种方式读取和写入zlib压缩的流。 – Ferruccio 2012-02-28 21:29:34