aboutsummaryrefslogtreecommitdiff
path: root/src/bzip2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bzip2.cpp')
-rw-r--r--src/bzip2.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/bzip2.cpp b/src/bzip2.cpp
index b8c0f74..433fc91 100644
--- a/src/bzip2.cpp
+++ b/src/bzip2.cpp
@@ -12,14 +12,11 @@ Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) :
12 12
13Bu::BZip2::~BZip2() 13Bu::BZip2::~BZip2()
14{ 14{
15 printf("-> Bu::BZip2::~BZip2()\n");
16 stop(); 15 stop();
17} 16}
18 17
19void Bu::BZip2::start() 18void Bu::BZip2::start()
20{ 19{
21 printf("-> Bu::BZip2::start()\n");
22 printf("Hey, it's starting...\n");
23 bzState.state = NULL; 20 bzState.state = NULL;
24 bzState.bzalloc = NULL; 21 bzState.bzalloc = NULL;
25 bzState.bzfree = NULL; 22 bzState.bzfree = NULL;
@@ -31,11 +28,11 @@ void Bu::BZip2::start()
31 28
32void Bu::BZip2::stop() 29void Bu::BZip2::stop()
33{ 30{
34 printf("-> Bu::BZip2::stop()\n");
35 if( bzState.state ) 31 if( bzState.state )
36 { 32 {
37 if( bReading ) 33 if( bReading )
38 { 34 {
35 BZ2_bzDecompressEnd( &bzState );
39 } 36 }
40 else 37 else
41 { 38 {
@@ -81,13 +78,39 @@ size_t Bu::BZip2::read( void *pData, size_t nBytes )
81 if( !bzState.state ) 78 if( !bzState.state )
82 { 79 {
83 bReading = true; 80 bReading = true;
81 BZ2_bzDecompressInit( &bzState, 0, 0 );
82 bzState.next_in = pBuf;
83 bzState.avail_in = 0;
84 } 84 }
85 if( bReading == false ) 85 if( bReading == false )
86 throw ExceptionBase("This bzip2 filter is in writing mode, you can't read."); 86 throw ExceptionBase("This bzip2 filter is in writing mode, you can't read.");
87 //bzState.next_in = pData; 87
88 //bzState.avail_in = nSizeIn; 88 int nRead = 0;
89 int nReadTotal = bzState.total_out_lo32;
90 for(;;)
91 {
92 bzState.next_out = (char *)pData;
93 bzState.avail_out = nBytes;
94 int ret = BZ2_bzDecompress( &bzState );
89 95
90 //printf("%db at [%08X] (%db)\n", bzState.avail_in, (uint32_t)bzState.next_in, bzState.total_in_lo32 ); 96 nReadTotal += nRead-bzState.avail_out;
97
98 if( ret == BZ_STREAM_END )
99 {
100 return nBytes-bzState.avail_out;
101 }
102
103 if( bzState.avail_out )
104 {
105 nRead = rNext.read( pBuf, nBufSize );
106 bzState.next_in = pBuf;
107 bzState.avail_in = nRead;
108 }
109 else
110 {
111 return nBytes-bzState.avail_out;
112 }
113 }
91 return 0; 114 return 0;
92} 115}
93 116