[bzip2 iostreams] [serialization] How to serialize an object into a bzip2 file and vice versa.
Hi. I right now managed to store objects via serialization onto harddisk. Because these files are still big and i used the textstream to serialize the object i decided to shrink the files...so far the plan :) I rebuild the iostreams with bzip support (that was also quite a pain ;) and now i can decompress a simple precompressed text file easily: int main() { using namespace std; using namespace boost::iostreams; ifstream file("E:\\test.txt.bz2", ios_base::in | ios_base::binary); filtering_streambuf<input> in; in.push(bzip2_decompressor()); in.push(file); ofstream fileOutput("E:\\test2.text"); copy(in,fileOutput); } But if i try to decompress a file which i serialized, bzip just runs forever doing nothing. SO my first question is, if someone knows why the serialized compressed files can not be decompressed. My second question is, if it is possible to serialize directly into a compressed bz2 file. I really looked around in the internet but still cannot get a clue so please respond. http://www.codeproject.com/KB/stl/zipstream.aspx?fid=16084&df=90&mpp=25&sort=Position&select=737834&tid=1192811 http://lists.boost.org/Archives/boost/2003/10/53755.php Thanks, SK
Sebastian Korf wrote:
int main() { using namespace std; using namespace boost::iostreams; ifstream file("E:\\test.txt.bz2", ios_base::in | ios_base::binary); filtering_streambuf<input> in; in.push(bzip2_decompressor()); in.push(file); ofstream fileOutput("E:\\test2.text"); copy(in,fileOutput); }
But if i try to decompress a file which i serialized, bzip just runs forever doing nothing.
There are several open tickets which deal with (de-)compression with iostreams. I had problems with zip, bzip and istreams myself. I found that ostreams work where istreams don't: https://svn.boost.org/trac/boost/ticket/2411 Unfortunately, with gzip decompression, ostreams sometimes fail but istreams work: https://svn.boost.org/trac/boost/ticket/2415 An infinite loop also has been reported before (in case of invalid input) https://svn.boost.org/trac/boost/ticket/2783 I also wrote a test program some time ago to determine the best compression method for my purposes, see attachment. HTH Regards, Roland
participants (2)
-
Roland Bock
-
Sebastian Korf