I'd like to use boost::iostreams
to compress log files, and hope that the logs are stored successfully in all cases. Can I reset an object of boost::filtering_stream
class automatically when a program is aborted by assertion failures?
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>
namespace io = boost::iostreams;
int main() {
io::filtering_ostream out;
out.push(io::gzip_compressor());
out.push(io::file_sink("my_file.txt.gz"));
for (auto i = 0; i < 100; ++i) {
if (i > 50) {
// Can I flush the stream without explicitly calling
// filtering_ostream::reset()?
// out.reset();
assert(false);
}
out << i << '\n';
}
}