Im trying to compress a file using boost library (gzip). Its a simple task: lets suppose i have the file data.xml and I need to compress it to data.xml.gz. I can even use the default compression values, doesn't matter.
I tryed to look up in google and BOOST pages but with no success.
I have the following:
bool SyncFrequencyHistory::frequencyHistoryCompressFile(void)
{
printf("\r\n===== ACTION: frequencyHistoryCompressFile =====\r\n");
std::ifstream inStream(FREQUENCY_HISTORY_FILE, std::ios_base::in);
std::ofstream outStream(FREQUENCY_HISTORY_FILE_GZIP, std::ios_base::out);
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::gzip_compressor());
out.push(outStream);
boost::iostreams::copy(in, out);
return true;
}
FREQUENCY_HISTORY_FILE have the full location of the XML file
FREQUENCY_HISTORY_FILE_GZIP have the full location for the XML.GZ file
I know almost all code is wrong, but i have no idea who to write it the correct way.
Based on the following tutorial, I believe your code should be:
bool SyncFrequencyHistory::frequencyHistoryCompressFile(void)
{
printf("\r\n===== ACTION: frequencyHistoryCompressFile =====\r\n");
std::ifstream inStream(FREQUENCY_HISTORY_FILE, std::ios_base::in);
std::ofstream outStream(FREQUENCY_HISTORY_FILE_GZIP, std::ios_base::out);
boost::iostreams::filtering_streambuf< boost::iostreams::input> in;
in.push( boost::iostreams::gzip_compressor());
in.push( inStream );
boost::iostreams::copy(in, outStream);
return true;
}
Basically, you read the input, compress it and saves the dat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With