c++ - boost filtering_istream gzip_decompressor 未压缩文件大小

标签 c++ boost gzip

我正在使用 boost 过滤流对象来读取压缩文件。效果很好! 我想显示已处理文件数量的进度条。我需要找到输入的未压缩文件大小。 gzip 解压缩程序是否可以访问 gzip 文件的原始文件大小?我在 boost gzip_decompressor reference 上找不到它页。进度对话框真的是目标,还有其他方法可以找出压缩文件中的位置吗?

    // 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
    }

最佳答案

你想要的信息肯定在那里(未压缩的数据大小记录在 gzip 文件的最后 4 个字节中,(参见 GZIP spec)但查看 boost 库的 header (参见 here)它没有暴露在任何地方。它似乎唯一被查看的地方是在进行检查以确保 read_footer 中没有损坏时。 您可以自己直接从文件中读取值(只需将最后 4 个字节组装成一个 int,注意它们的顺序(再次参见 GZIP 规范)),或者使用不同的库进行解压缩。

关于c++ - boost filtering_istream gzip_decompressor 未压缩文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1764082/

相关文章:

c++ QThread和boost回调函数

C++ Virtual boost::any 继承

java - 在java中压缩和解压缩大尺寸数据?

java - 使用 GzipInputStream 解压 byte[]

python - 将数据帧作为压缩的 csv 直接上传到 s3,而不将其保存在本地计算机上

c++ - opencv 删除视频提要到帧

c++ - c/c++ 库存位图使用十六进制字母并转换回来

c++ - 四叉树不会插入节点或拆分

C++ 模板<运算符>

c++ - (shared_ptr+weak_ptr)兼容原始指针的设计