From: Christian P. <cp...@us...> - 2005-01-06 19:22:39
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18331/src/IO Modified Files: ZLib.cpp BZip2.cpp Makefile.am Log Message: Fixed [ZLib|BZip2]OutputStream: only finish when we have compressed something Index: ZLib.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/ZLib.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ZLib.cpp 6 Jan 2005 17:24:22 -0000 1.3 +++ ZLib.cpp 6 Jan 2005 19:22:24 -0000 1.4 @@ -150,13 +150,16 @@ bool ZLibOutputStream::finish() throw(ZLibError) { - int ret = ::deflate(_strm, Z_FINISH); - // not enough buffer was avail... should call finish() again - if(ret == Z_OK) - return false; - - if(ret != Z_STREAM_END) - throw ZLibError(Z_BUF_ERROR, 0, "Could not finish stream", P_SOURCEINFO); + if(_strm->total_in > 0) + { + int ret = ::deflate(_strm, Z_FINISH); + // not enough buffer was avail... should call finish() again + if(ret == Z_OK) + return false; + + if(ret != Z_STREAM_END) + throw ZLibError(Z_BUF_ERROR, 0, "Could not finish stream", P_SOURCEINFO); + } return true; } Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.am 6 Jan 2005 18:30:33 -0000 1.5 +++ Makefile.am 6 Jan 2005 19:22:24 -0000 1.6 @@ -2,5 +2,5 @@ METASOURCES = AUTO lib_LTLIBRARIES = libpclasses_io.la -libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp +libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp BZip2IOFilter.cpp libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la -lz -lbz2 Index: BZip2.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/BZip2.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- BZip2.cpp 6 Jan 2005 18:30:33 -0000 1.1 +++ BZip2.cpp 6 Jan 2005 19:22:24 -0000 1.2 @@ -130,7 +130,7 @@ ((bz_stream*)_strm)->avail_in = count; int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_RUN); - if(ret != BZ_OK) + if(ret != BZ_RUN_OK) throw BZip2Error(ret, "Could not compress", P_SOURCEINFO); // return with number of bytes consumed ... @@ -141,19 +141,22 @@ void BZip2OutputStream::sync() throw(BZip2Error) { int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FLUSH); - if(ret != BZ_OK) + if(ret != BZ_FLUSH_OK) throw BZip2Error(ret, "Could not flush stream", P_SOURCEINFO); } bool BZip2OutputStream::finish() throw(BZip2Error) { - int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FINISH); - // not enough buffer was avail... should call finish() again - if(ret == BZ_FINISH_OK) - return false; - - if(ret != BZ_STREAM_END) - throw BZip2Error(BZ_OUTBUFF_FULL, "Could not finish stream", P_SOURCEINFO); + if(((bz_stream*)_strm)->total_in_lo32 > 0) + { + int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FINISH); + // not enough buffer was avail... should call finish() again + if(ret == BZ_FINISH_OK) + return false; + + if(ret != BZ_STREAM_END) + throw BZip2Error(BZ_OUTBUFF_FULL, "Could not finish stream", P_SOURCEINFO); + } return true; } @@ -162,6 +165,10 @@ { ((bz_stream*)_strm)->next_out = _buffer; ((bz_stream*)_strm)->avail_out = _bufferSize; + ((bz_stream*)_strm)->total_in_lo32 = 0; + ((bz_stream*)_strm)->total_in_hi32 = 0; + ((bz_stream*)_strm)->total_out_lo32 = 0; + ((bz_stream*)_strm)->total_out_hi32 = 0; } BZip2InputStream::BZip2InputStream(size_t bufferSize) throw(BZip2Error) |