これは Poco に組み込まれています (C++ ライブラリ/フレームワーク、多くのユーティリティ、ネットワーキングなど)。サンプルプログラムは次のとおりです。
#include <iostream>
#include <sstream>
#include <Poco/InflatingStream.h>
#include <Poco/DeflatingStream.h>
#include <Poco/StreamCopier.h>
int main() {
std::ostringstream stream1;
Poco::DeflatingOutputStream
gzipper(stream1, Poco::DeflatingStreamBuf::STREAM_GZIP);
gzipper << "Hello World!";
gzipper.close();
std::string zipped_string = stream1.str();
std::cout << "zipped_string: [" << zipped_string << "]\n";
std::ostringstream stream2;
Poco::InflatingOutputStream
gunzipper(stream2, Poco::InflatingStreamBuf::STREAM_GZIP);
gunzipper << zipped_string;
gunzipper.close();
std::string unzipped_string = stream2.str();
std::cout << "unzipped_string back: [" << unzipped_string << "]\n";
return 0;
}
良い点は、上記の ostringstreams の代わりに、Poco gzipping ストリームをファイルなどに接続できることです..