I have set of compressed files. I have to decompress all the files and create one big file. below code is working fine, but I don't want to use std::stringstream because the files are big and I don't want to create intermediate copies of the file content.
If I try to use boost::iostreams::copy(inbuf, tempfile);
directly, it is closing the file(tmpfile) automatically. Is there any better way to copy the content ? or at least, can I avoid closing of this file automatically?
std::ofstream tempfile("/tmp/extmpfile", std::ios::binary);
for (set<std::string>::iterator it = files.begin(); it != files.end(); ++it)
{
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);
//closes tempfile automatically!!
//boost::iostreams::copy(inbuf, tempfile);
std::stringstream out;
boost::iostreams::copy(inbuf, out);
tempfile << out.str();
}
tempfile.close();