我正在使用 boost 过滤流对象来读取 gzipped 文件。效果很好!我想显示已处理文件量的进度条。我需要找到输入的未压缩文件大小。gzip 解压器是否可以访问 gzip 文件中的原始文件大小?我在boost gzip_decompressor 参考页面上找不到它。真的进度对话框是目标,是否有另一种方法来确定压缩文件中的位置?
// gets compressed file size, need uncompressed size
boost::uintmax_t fs = boost::filesystem::file_size (
boost::filesystem::path (fname)
);
std::ifstream file (fname, std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_istream in;
in.push (boost::iostreams::gzip_decompressor());
in.push (file);
std::string line;
size_t bytes_read = 0;
while (in)
{
std::getline (in, line);
bytes_read += line.size ();
// progress dlg with bytes_read / uncompressed size
}
Run Code Online (Sandbox Code Playgroud)