aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bzip2.cpp31
-rw-r--r--src/tests/bzip2.cpp10
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 )
64 switch( code ) 64 switch( code )
65 { 65 {
66 case BZ_OK: 66 case BZ_OK:
67 printf("<BZ_OK>\n"); return;
68 case BZ_RUN_OK:
69 printf("<BZ_RUN_OK>\n"); return;
70 case BZ_FLUSH_OK:
71 printf("<BZ_FLUSH_OK>\n"); return;
72 case BZ_FINISH_OK:
73 printf("<BZ_FINISH_OK>\n"); return;
67 return; 74 return;
68 75
69 case BZ_CONFIG_ERROR: 76 case BZ_CONFIG_ERROR:
@@ -117,20 +124,36 @@ size_t Bu::BZip2::read( void *pData, size_t nBytes )
117 { 124 {
118 bzState.next_out = (char *)pData; 125 bzState.next_out = (char *)pData;
119 bzState.avail_out = nBytes; 126 bzState.avail_out = nBytes;
127 printf(" (pre) in: %db, out: %db\n", bzState.avail_in, bzState.avail_out );
120 int ret = BZ2_bzDecompress( &bzState ); 128 int ret = BZ2_bzDecompress( &bzState );
129 printf("(post) in: %db, out: %db\n", bzState.avail_in, bzState.avail_out );
121 130
122 nReadTotal += nRead-bzState.avail_out; 131 nReadTotal += nRead-bzState.avail_out;
123 132
124 if( ret == BZ_STREAM_END ) 133 if( ret == BZ_STREAM_END )
125 { 134 {
135 printf("<BZ_STREAM_END>\n");
136 if( bzState.avail_in > 0 )
137 {
138 if( rNext.canSeek() )
139 {
140 rNext.seek( -bzState.avail_in );
141 }
142 }
126 return nBytes-bzState.avail_out; 143 return nBytes-bzState.avail_out;
127 } 144 }
145 bzError( ret );
128 146
129 if( bzState.avail_out ) 147 if( bzState.avail_out )
130 { 148 {
131 nRead = rNext.read( pBuf, nBufSize ); 149 printf("Still more to fill, in: %db, out: %db\n", bzState.avail_in, bzState.avail_out );
132 bzState.next_in = pBuf; 150
133 bzState.avail_in = nRead; 151 if( bzState.avail_in == 0 )
152 {
153 nRead = rNext.read( pBuf, nBufSize );
154 bzState.next_in = pBuf;
155 bzState.avail_in = nRead;
156 }
134 } 157 }
135 else 158 else
136 { 159 {
@@ -158,7 +181,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes )
158 bzState.avail_out = nBufSize; 181 bzState.avail_out = nBufSize;
159 bzState.next_out = pBuf; 182 bzState.next_out = pBuf;
160 183
161 BZ2_bzCompress( &bzState, BZ_RUN ); 184 bzError( BZ2_bzCompress( &bzState, BZ_RUN ) );
162 185
163 if( bzState.avail_out < nBufSize ) 186 if( bzState.avail_out < nBufSize )
164 { 187 {
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[] )
6 char buf[1024]; 6 char buf[1024];
7 size_t nRead; 7 size_t nRead;
8 8
9 Bu::File f( "test.bz2", "rb" ); 9 Bu::File f( "test.bz2", "wb" );
10 Bu::BZip2 bz2( f ); 10 Bu::BZip2 bz2( f );
11 11
12 Bu::File fin( argv[1], "wb"); 12 Bu::File fin( argv[1], "rb");
13 13
14 for(;;) 14 for(;;)
15 { 15 {
16 nRead = bz2.read( buf, 1024 ); 16 nRead = fin.read( buf, 1024 );
17 if( nRead > 0 ) 17 if( nRead > 0 )
18 fin.write( buf, nRead ); 18 bz2.write( buf, nRead );
19 if( bz2.isEOS() ) 19 if( fin.isEOS() )
20 break; 20 break;
21 } 21 }
22} 22}