bzip2_compressor help
I know that I'm doing something stupid but it isn't obvious to me what. I'm trying to write a compressed file using: namespace BI = boost::iostreams; BI::filtering_ostream out; std::fstream mfile("test.gz", std::ios::binary|std::ios::out); out.push(BI::bzip2_compressor()); out.push(mfile); out << "This is a gz file" << endl; but when I do so, the file is always empty. Commenting out the push of the bzip2_compressor works like I'd expect. Any help for a newbie? Thanks B
namespace BI = boost::iostreams; BI::filtering_ostream out; std::fstream mfile("test.gz", std::ios::binary|std::ios::out); out.push(BI::bzip2_compressor()); out.push(mfile); out << "This is a gz file" << endl;
Maybe you should replace fstream by BI::file_sink? but note that the file is closed (and fully written) only when the variable out is destroyed so that you need to enclose your code in { ... } if you need to use the file just after out <<...<< endl; Frédéric
participants (2)
-
Bryan S
-
Frédéric Bron