我目前正在尝试将一些涉及DeflateStream用法的C#代码移植到没有.NET框架支持的标准C++中。这类函数的一个示例是:
public static byte[] ReadCompressed(this Stream stream)
{
var reader = new BinaryReader(stream);
int len = reader.ReadInt32();
var array = new byte[len];
var ds = new DeflateStream(stream, CompressionMode.Decompress);
ds.Read(array, 0, len);
ds.Close();
return array;
}只是想知道,有没有一种简单的方法可以将上面的代码移植到C++中?谢谢!
发布于 2012-01-04 05:51:27
您可能想要使用zlib。在C++中,最简单的方法是使用Boost wrapper for it。
我不完全确定您的示例是做什么的,但下面是如何读取zlib压缩文件并将其内容写入stdout (改编自文档中的一个示例):
namespace io = boost::iostreams;
std::ifstream file("hello.z", std::ios_base::binary);
io::filtering_streambuf<io::input> in;
in.push(io::zlib_decompressor());
in.push(file);
io::copy(in, std::cout);https://stackoverflow.com/questions/8719034
复制相似问题