부스트 IOStreams가 스트림을 닫아서는 안된다는 것을 알 수있는 방법이 있습니다. 그래도 std::ostream
대신에 boost::iostream::stream<>
을 사용해야한다고 생각합니다.
echo a > a
echo b > b
gzip a b
처럼
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
int main() {
std::filebuf tempfilebuf;
tempfilebuf.open("/tmp/extmpfile", std::ios::binary|std::ios::out);
std::set<std::string> files { "a.gz", "b.gz" };
for (std::set<std::string>::iterator it = files.begin(); it != files.end(); ++it)
{
std::string filename(*it);
std::ifstream gzfile(filename.c_str(), std::ios::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::gzip_decompressor());
inbuf.push(gzfile);
std::ostream tempfile(&tempfilebuf);
boost::iostreams::copy(inbuf, tempfile);
}
tempfilebuf.close();
}
Live On Coliru
샘플 데이터를 사용하여 다음 작업에 나타납니다
내 간단한 해결 방법은 하나의 std::filebuf
객체와 관련된 임시 std::ostream
를 사용하는 것이 었습니다
겐 extmpfile
포함
a
b
대상 파일 상단에 간단한 출력 필터를 사용합니까? –