Boost logo

Boost Users :

From: Jabin Reinhold (jdreinhold_at_[hidden])
Date: 2007-04-02 09:57:41


I’m trying to use the iostreams gzip compression on xml serializations
produced using boost::serialization and I’m having a bit of trouble with it.
The variable to be serialized is savedClass. As shown below, I create the
serialization, save to a file with gzip_compressor, then read it from the
file with gzip_decompressor.

My issue is that at the end of the code, test1.xml(~10k) and test2.xml(~12k)
are not identical. Test2.xml has some extraneous characters added to the end
(~2k worth). I assume these are leftovers from a memcopy somewhere, but I’m
not sure why. I have the same effect when I use zlib_compressor as well.
What is wrong with my usage of the library(s)?

////////////////////////////////////////////////////////////////
std::strstream sStream;
if(true)
{
      //Scope used to ensure that the archive is fully processed
      boost::archive::xml_oarchive oArchive(sStream);
      oArchive << BOOST_SERIALIZATION_NVP(savedClass);
}
std::ofstream oStreamXML1( "c:\\test1.xml", std::ios::out );
oStreamXML1 << sStream.str();

if(true)
{
      //Scope used to ensure that the archive is fully processed
      std::ofstream file("c:\\test.gz", std::ios_base::out |
std::ios_base::binary);
      boost::iostreams::filtering_streambuf<boost::iostreams::output>
outStream;
      outStream.push(boost::iostreams::gzip_compressor());
      outStream.push(file);
      boost::iostreams::copy(sStream, outStream);
}

std::strstream sStream2;
if(true)
{
      //Scope used to ensure that the archive is fully processed
      std::ifstream file2("c:\\test.gz", std::ios_base::in |
std::ios_base::binary);
      boost::iostreams::filtering_streambuf<boost::iostreams::input>
inStream;
      inStream.push(boost::iostreams::gzip_decompressor());
      inStream.push(file2);
      boost::iostreams::copy(inStream, sStream2);
}

std::ofstream oStreamXML2( "c:\\test2.xml", std::ios::out );
oStreamXML2 << sStream2.str();
////////////////////////////////////////////////////////////////


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net