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 +++++++++++----- src/bzip2.h | 3 +++ src/file.cpp | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') 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; +} + diff --git a/src/bzip2.h b/src/bzip2.h index fd0ba5c..7ca61b4 100644 --- a/src/bzip2.h +++ b/src/bzip2.h @@ -32,6 +32,8 @@ namespace Bu virtual bool isOpen(); + size_t getCompressedSize(); + private: void bzError( int code ); bz_stream bzState; @@ -39,6 +41,7 @@ namespace Bu int nCompression; char *pBuf; uint32_t nBufSize; + size_t sTotalOut; }; } diff --git a/src/file.cpp b/src/file.cpp index 6228ba9..1c26001 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -93,6 +93,7 @@ void Bu::File::seek( long offset ) throw FileException("File not open."); lseek( fd, offset, SEEK_CUR ); + bEos = false; } void Bu::File::setPos( long pos ) @@ -101,6 +102,7 @@ void Bu::File::setPos( long pos ) throw FileException("File not open."); lseek( fd, pos, SEEK_SET ); + bEos = false; } void Bu::File::setPosEnd( long pos ) @@ -109,6 +111,7 @@ void Bu::File::setPosEnd( long pos ) throw FileException("File not open."); lseek( fd, pos, SEEK_END ); + bEos = false; } bool Bu::File::isEos() -- cgit v1.2.3