From 1b7caf3368675eb6825e0dca77782a141dfa0392 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 23 Sep 2009 23:19:38 +0000 Subject: Wow, ok, file was broken on changing position in the stream, it wouldn't reset the end of stream flag. Now it does reset it, and assumes that you've placed the position not at the end, if you have, it will detect it again immediately upon read. BZip2 now provides a method of getting the number of bytes written out, i.e. the compressed size of the output, I have to figure out the input side next... --- src/bzip2.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/bzip2.cpp') diff --git a/src/bzip2.cpp b/src/bzip2.cpp index 0a56f83..7f6e45e 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp @@ -12,7 +12,8 @@ using namespace Bu; Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : Bu::Filter( rNext ), - nCompression( nCompression ) + nCompression( nCompression ), + sTotalOut( 0 ) { TRACE( nCompression ); start(); @@ -50,7 +51,7 @@ size_t Bu::BZip2::stop() } else { - size_t sTotal = 0; +// size_t sTotal = 0; for(;;) { bzState.next_in = NULL; @@ -60,7 +61,7 @@ size_t Bu::BZip2::stop() int res = BZ2_bzCompress( &bzState, BZ_FINISH ); if( bzState.avail_out < nBufSize ) { - sTotal += rNext.write( pBuf, nBufSize-bzState.avail_out ); + sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); } if( res == BZ_STREAM_END ) break; @@ -68,7 +69,7 @@ size_t Bu::BZip2::stop() BZ2_bzCompressEnd( &bzState ); delete[] pBuf; pBuf = NULL; - return sTotal; + return sTotalOut; } } return 0; @@ -182,7 +183,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) if( bReading == true ) throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); - size_t sTotalOut = 0; +// size_t sTotalOut = 0; bzState.next_in = (char *)pData; bzState.avail_in = nBytes; for(;;) @@ -209,3 +210,8 @@ bool Bu::BZip2::isOpen() return (bzState.state != NULL); } +size_t Bu::BZip2::getCompressedSize() +{ + return sTotalOut; +} + -- cgit v1.2.3