如何从boost的gzip_decompressor()获取gzip_params [英] How to get gzip_params from boost's gzip_decompressor()
本文介绍了如何从boost的gzip_decompressor()获取gzip_params的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过以下链接使用boost gzip_decompressor(): 我如何阅读使用Boost IOStreams的界面逐行处理Gzip文件?
I am using the boost gzip_decompressor() from the following link: How can I read line-by-line using Boost IOStreams' interface for Gzip files?
读取gzip文件可以正常工作,但是如何读取gzip_params?我想知道存储在gzip_params.file_name中的原始文件名.
Reading the gzip file works fine, but how do I read the gzip_params? I want to know the original file name that's stored in the gzip_params.file_name.
推荐答案
一个很好的问题.
解决方案是使用component<N, T>
获取指向实际解压缩器实例的指针:
The solution is to use component<N, T>
to get a pointer to the actual decompressor instance:
#include <iostream>
#include <fstream>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
std::ifstream file("file.gz", std::ios_base::in | std::ios_base::binary);
try {
boost::iostreams::filtering_istream in;
using gz_t = boost::iostreams::gzip_decompressor;
in.push(gz_t());
in.push(file);
for(std::string str; std::getline(in, str); )
{
std::cout << "Processed line " << str << '\n';
}
if (gz_t* gz = in.component<0, gz_t>()) {
std::cout << "Original filename: " << gz->file_name() << "\n";
std::cout << "Original mtime: " << gz->mtime() << "\n";
std::cout << "Zip comment: " << gz->comment() << "\n";
}
}
catch(const boost::iostreams::gzip_error& e) {
std::cout << e.what() << '\n';
}
}
使用准备样品文件
gzip testj.txt
mv testj.txt.gz file.gz
打印
Processed line Hello world
Original filename: testj.txt
Original mtime: 1518987084
Zip comment:
这篇关于如何从boost的gzip_decompressor()获取gzip_params的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文