aboutsummaryrefslogtreecommitdiff
path: root/src/bzip2.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-09-23 23:19:38 +0000
committerMike Buland <eichlan@xagasoft.com>2009-09-23 23:19:38 +0000
commit1b7caf3368675eb6825e0dca77782a141dfa0392 (patch)
tree01fb357534875c7a69199e4dd3f0c9d8810810e2 /src/bzip2.cpp
parent319a773dfcb187bc7e87ae6d64df3b6b6ec4831a (diff)
downloadlibbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.tar.gz
libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.tar.bz2
libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.tar.xz
libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.zip
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...
Diffstat (limited to '')
-rw-r--r--src/bzip2.cpp16
1 files changed, 11 insertions, 5 deletions
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;
12 12
13Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : 13Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) :
14 Bu::Filter( rNext ), 14 Bu::Filter( rNext ),
15 nCompression( nCompression ) 15 nCompression( nCompression ),
16 sTotalOut( 0 )
16{ 17{
17 TRACE( nCompression ); 18 TRACE( nCompression );
18 start(); 19 start();
@@ -50,7 +51,7 @@ size_t Bu::BZip2::stop()
50 } 51 }
51 else 52 else
52 { 53 {
53 size_t sTotal = 0; 54// size_t sTotal = 0;
54 for(;;) 55 for(;;)
55 { 56 {
56 bzState.next_in = NULL; 57 bzState.next_in = NULL;
@@ -60,7 +61,7 @@ size_t Bu::BZip2::stop()
60 int res = BZ2_bzCompress( &bzState, BZ_FINISH ); 61 int res = BZ2_bzCompress( &bzState, BZ_FINISH );
61 if( bzState.avail_out < nBufSize ) 62 if( bzState.avail_out < nBufSize )
62 { 63 {
63 sTotal += rNext.write( pBuf, nBufSize-bzState.avail_out ); 64 sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out );
64 } 65 }
65 if( res == BZ_STREAM_END ) 66 if( res == BZ_STREAM_END )
66 break; 67 break;
@@ -68,7 +69,7 @@ size_t Bu::BZip2::stop()
68 BZ2_bzCompressEnd( &bzState ); 69 BZ2_bzCompressEnd( &bzState );
69 delete[] pBuf; 70 delete[] pBuf;
70 pBuf = NULL; 71 pBuf = NULL;
71 return sTotal; 72 return sTotalOut;
72 } 73 }
73 } 74 }
74 return 0; 75 return 0;
@@ -182,7 +183,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes )
182 if( bReading == true ) 183 if( bReading == true )
183 throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); 184 throw ExceptionBase("This bzip2 filter is in reading mode, you can't write.");
184 185
185 size_t sTotalOut = 0; 186// size_t sTotalOut = 0;
186 bzState.next_in = (char *)pData; 187 bzState.next_in = (char *)pData;
187 bzState.avail_in = nBytes; 188 bzState.avail_in = nBytes;
188 for(;;) 189 for(;;)
@@ -209,3 +210,8 @@ bool Bu::BZip2::isOpen()
209 return (bzState.state != NULL); 210 return (bzState.state != NULL);
210} 211}
211 212
213size_t Bu::BZip2::getCompressedSize()
214{
215 return sTotalOut;
216}
217