From 408aca47fd423e7c4c38665b892a13c1c9fb1e9a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 11 Jun 2007 07:31:52 +0000 Subject: Few minor tweaks to bzip2, it reports errors now...and there's a bug in odpm that could be in this, but it's going to be hard to tell... --- src/bzip2.cpp | 31 +++++++++++++++++++++++++++---- src/tests/bzip2.cpp | 10 +++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/bzip2.cpp b/src/bzip2.cpp index 5423a10..6bb1429 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp @@ -64,6 +64,13 @@ void Bu::BZip2::bzError( int code ) switch( code ) { case BZ_OK: + printf("\n"); return; + case BZ_RUN_OK: + printf("\n"); return; + case BZ_FLUSH_OK: + printf("\n"); return; + case BZ_FINISH_OK: + printf("\n"); return; return; case BZ_CONFIG_ERROR: @@ -117,20 +124,36 @@ size_t Bu::BZip2::read( void *pData, size_t nBytes ) { bzState.next_out = (char *)pData; bzState.avail_out = nBytes; + printf(" (pre) in: %db, out: %db\n", bzState.avail_in, bzState.avail_out ); int ret = BZ2_bzDecompress( &bzState ); + printf("(post) in: %db, out: %db\n", bzState.avail_in, bzState.avail_out ); nReadTotal += nRead-bzState.avail_out; if( ret == BZ_STREAM_END ) { + printf("\n"); + if( bzState.avail_in > 0 ) + { + if( rNext.canSeek() ) + { + rNext.seek( -bzState.avail_in ); + } + } return nBytes-bzState.avail_out; } + bzError( ret ); if( bzState.avail_out ) { - nRead = rNext.read( pBuf, nBufSize ); - bzState.next_in = pBuf; - bzState.avail_in = nRead; + printf("Still more to fill, in: %db, out: %db\n", bzState.avail_in, bzState.avail_out ); + + if( bzState.avail_in == 0 ) + { + nRead = rNext.read( pBuf, nBufSize ); + bzState.next_in = pBuf; + bzState.avail_in = nRead; + } } else { @@ -158,7 +181,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) bzState.avail_out = nBufSize; bzState.next_out = pBuf; - BZ2_bzCompress( &bzState, BZ_RUN ); + bzError( BZ2_bzCompress( &bzState, BZ_RUN ) ); if( bzState.avail_out < nBufSize ) { diff --git a/src/tests/bzip2.cpp b/src/tests/bzip2.cpp index ef9328f..683d3d7 100644 --- a/src/tests/bzip2.cpp +++ b/src/tests/bzip2.cpp @@ -6,17 +6,17 @@ int main( int argc, char *argv[] ) char buf[1024]; size_t nRead; - Bu::File f( "test.bz2", "rb" ); + Bu::File f( "test.bz2", "wb" ); Bu::BZip2 bz2( f ); - Bu::File fin( argv[1], "wb"); + Bu::File fin( argv[1], "rb"); for(;;) { - nRead = bz2.read( buf, 1024 ); + nRead = fin.read( buf, 1024 ); if( nRead > 0 ) - fin.write( buf, nRead ); - if( bz2.isEOS() ) + bz2.write( buf, nRead ); + if( fin.isEOS() ) break; } } -- cgit v1.2.3