如何使用zlib解压缩gzipstream [英] How to decompress gzipstream with zlib

查看:396
本文介绍了如何使用zlib解压缩gzipstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我我需要使用哪个函数来解压缩一个已经用vb.net的gzipstream压缩的字节数组。我想使用zlib。

Can someone tell me which function I need to use in order to decompress a byte array that has been compressed with vb.net's gzipstream. I would like to use zlib.

我已经包含了zlib.h但是我还没有找出我应该使用的功能。 / p>

I've included the zlib.h but I haven't been able to figure out what function(s) I should use.

推荐答案

您可以查看 The Boost Iostreams Library

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

std::ifstream file;
file.exceptions(std::ios::failbit | std::ios::badbit);
file.open(filename, std::ios_base::in | std::ios_base::binary);

boost::iostreams::filtering_stream<boost::iostreams::input> decompressor;
decompressor.push(boost::iostreams::gzip_decompressor());
decompressor.push(file);

然后逐行解压缩:

for(std::string line; getline(decompressor, line);) {
    // decompressed a line
}

或将整个文件导入数组:

Or entire file into an array:

std::vector<char> data(
      std::istreambuf_iterator<char>(decompressor)
    , std::istreambuf_iterator<char>()
    );

这篇关于如何使用zlib解压缩gzipstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆