BoostIOStreamsをご覧ください
例として、コマンドラインから次のファイルを作成しました。
$ echo "this is the first line" > file
$ echo "this is the second line" >> file
$ echo "this is the third line" >> file
$ bzip2 file
$ file file.bz2
file.bz2: bzip2 compressed data, block size = 900k
次に、boost :: iostreams :: filtering_istreamを使用して、file.bz2という名前の削除されたbzip2ファイルの結果を読み取りました。
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <iostream>
namespace io = boost::iostreams;
/* To Compile:
g++ -Wall -o ./bzipIOStream ./bzipIOStream.cpp -lboost_iostreams
*/
int main(){
io::filtering_istream in;
in.push(io::bzip2_decompressor());
in.push(io::file_source("./file.bz2"));
while(in.good()){
char c = in.get();
if(in.good()){
std::cout << c;
}
}
return 0;
}
コマンドを実行した結果、解凍されたデータが得られます。
$ ./bzipIOStream
this is the first line
this is the second line
this is the third line
もちろん、データを1文字ずつ読んだわけではありませんが、例を単純にしようとしていました。