aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-10-24 16:30:39 +0000
committerMike Buland <eichlan@xagasoft.com>2011-10-24 16:30:39 +0000
commit9cb2695ad318dcda83a353b03c21b4fd71d0f9d6 (patch)
tree0dff744dc9d7348ee922e4f2630ca8acfc438b6f /src
parente2fbc414b932ae9fd305c8e9fc315a306a876a09 (diff)
downloadlibbu++-9cb2695ad318dcda83a353b03c21b4fd71d0f9d6.tar.gz
libbu++-9cb2695ad318dcda83a353b03c21b4fd71d0f9d6.tar.bz2
libbu++-9cb2695ad318dcda83a353b03c21b4fd71d0f9d6.tar.xz
libbu++-9cb2695ad318dcda83a353b03c21b4fd71d0f9d6.zip
Made the encoder state opaque to the caller in Deflate and BZip2 to match Lzma.
That means that when you use Bu::Deflate, Bu::Bzip2, or Bu::Lzma you don't get any of the respective libraries' header files.
Diffstat (limited to 'src')
-rw-r--r--src/bzip2.cpp95
-rw-r--r--src/bzip2.h3
-rw-r--r--src/deflate.cpp120
-rw-r--r--src/deflate.h3
4 files changed, 120 insertions, 101 deletions
diff --git a/src/bzip2.cpp b/src/bzip2.cpp
index 0ff5444..ca007b0 100644
--- a/src/bzip2.cpp
+++ b/src/bzip2.cpp
@@ -8,10 +8,15 @@
8#include "bu/bzip2.h" 8#include "bu/bzip2.h"
9#include "bu/trace.h" 9#include "bu/trace.h"
10 10
11#include <bzlib.h>
12
13#define pState ((bz_stream *)prState)
14
11using namespace Bu; 15using namespace Bu;
12 16
13Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : 17Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) :
14 Bu::Filter( rNext ), 18 Bu::Filter( rNext ),
19 prState( NULL ),
15 nCompression( nCompression ), 20 nCompression( nCompression ),
16 sTotalOut( 0 ) 21 sTotalOut( 0 )
17{ 22{
@@ -28,10 +33,12 @@ Bu::BZip2::~BZip2()
28void Bu::BZip2::start() 33void Bu::BZip2::start()
29{ 34{
30 TRACE(); 35 TRACE();
31 bzState.state = NULL; 36
32 bzState.bzalloc = NULL; 37 prState = new bz_stream;
33 bzState.bzfree = NULL; 38 pState->state = NULL;
34 bzState.opaque = NULL; 39 pState->bzalloc = NULL;
40 pState->bzfree = NULL;
41 pState->opaque = NULL;
35 42
36 nBufSize = 64*1024; 43 nBufSize = 64*1024;
37 pBuf = new char[nBufSize]; 44 pBuf = new char[nBufSize];
@@ -40,13 +47,15 @@ void Bu::BZip2::start()
40Bu::size Bu::BZip2::stop() 47Bu::size Bu::BZip2::stop()
41{ 48{
42 TRACE(); 49 TRACE();
43 if( bzState.state ) 50 if( pState->state )
44 { 51 {
45 if( bReading ) 52 if( bReading )
46 { 53 {
47 BZ2_bzDecompressEnd( &bzState ); 54 BZ2_bzDecompressEnd( pState );
48 delete[] pBuf; 55 delete[] pBuf;
49 pBuf = NULL; 56 pBuf = NULL;
57 delete pState;
58 prState = NULL;
50 return 0; 59 return 0;
51 } 60 }
52 else 61 else
@@ -54,21 +63,23 @@ Bu::size Bu::BZip2::stop()
54// Bu::size sTotal = 0; 63// Bu::size sTotal = 0;
55 for(;;) 64 for(;;)
56 { 65 {
57 bzState.next_in = NULL; 66 pState->next_in = NULL;
58 bzState.avail_in = 0; 67 pState->avail_in = 0;
59 bzState.avail_out = nBufSize; 68 pState->avail_out = nBufSize;
60 bzState.next_out = pBuf; 69 pState->next_out = pBuf;
61 int res = BZ2_bzCompress( &bzState, BZ_FINISH ); 70 int res = BZ2_bzCompress( pState, BZ_FINISH );
62 if( bzState.avail_out < nBufSize ) 71 if( pState->avail_out < nBufSize )
63 { 72 {
64 sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); 73 sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out );
65 } 74 }
66 if( res == BZ_STREAM_END ) 75 if( res == BZ_STREAM_END )
67 break; 76 break;
68 } 77 }
69 BZ2_bzCompressEnd( &bzState ); 78 BZ2_bzCompressEnd( pState );
70 delete[] pBuf; 79 delete[] pBuf;
71 pBuf = NULL; 80 pBuf = NULL;
81 delete pState;
82 prState = NULL;
72 return sTotalOut; 83 return sTotalOut;
73 } 84 }
74 } 85 }
@@ -122,42 +133,42 @@ void Bu::BZip2::bzError( int code )
122Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes ) 133Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes )
123{ 134{
124 TRACE( pData, nBytes ); 135 TRACE( pData, nBytes );
125 if( !bzState.state ) 136 if( !pState->state )
126 { 137 {
127 bReading = true; 138 bReading = true;
128 BZ2_bzDecompressInit( &bzState, 0, 0 ); 139 BZ2_bzDecompressInit( pState, 0, 0 );
129 bzState.next_in = pBuf; 140 pState->next_in = pBuf;
130 bzState.avail_in = 0; 141 pState->avail_in = 0;
131 } 142 }
132 if( bReading == false ) 143 if( bReading == false )
133 throw ExceptionBase("This bzip2 filter is in writing mode, you can't read."); 144 throw ExceptionBase("This bzip2 filter is in writing mode, you can't read.");
134 145
135 int nRead = 0; 146 int nRead = 0;
136 int nReadTotal = bzState.total_out_lo32; 147 int nReadTotal = pState->total_out_lo32;
137 bzState.next_out = (char *)pData; 148 pState->next_out = (char *)pData;
138 bzState.avail_out = nBytes; 149 pState->avail_out = nBytes;
139 for(;;) 150 for(;;)
140 { 151 {
141 int ret = BZ2_bzDecompress( &bzState ); 152 int ret = BZ2_bzDecompress( pState );
142 153
143 nReadTotal += nRead-bzState.avail_out; 154 nReadTotal += nRead-pState->avail_out;
144 155
145 if( ret == BZ_STREAM_END ) 156 if( ret == BZ_STREAM_END )
146 { 157 {
147 if( bzState.avail_in > 0 ) 158 if( pState->avail_in > 0 )
148 { 159 {
149 if( rNext.isSeekable() ) 160 if( rNext.isSeekable() )
150 { 161 {
151 rNext.seek( -bzState.avail_in ); 162 rNext.seek( -pState->avail_in );
152 } 163 }
153 } 164 }
154 return nBytes-bzState.avail_out; 165 return nBytes-pState->avail_out;
155 } 166 }
156 bzError( ret ); 167 bzError( ret );
157 168
158 if( bzState.avail_out ) 169 if( pState->avail_out )
159 { 170 {
160 if( bzState.avail_in == 0 ) 171 if( pState->avail_in == 0 )
161 { 172 {
162 nRead = rNext.read( pBuf, nBufSize ); 173 nRead = rNext.read( pBuf, nBufSize );
163 if( nRead == 0 && rNext.isEos() ) 174 if( nRead == 0 && rNext.isEos() )
@@ -165,13 +176,13 @@ Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes )
165 throw Bu::ExceptionBase("Premature end of underlying " 176 throw Bu::ExceptionBase("Premature end of underlying "
166 "stream found reading bzip2 stream."); 177 "stream found reading bzip2 stream.");
167 } 178 }
168 bzState.next_in = pBuf; 179 pState->next_in = pBuf;
169 bzState.avail_in = nRead; 180 pState->avail_in = nRead;
170 } 181 }
171 } 182 }
172 else 183 else
173 { 184 {
174 return nBytes-bzState.avail_out; 185 return nBytes-pState->avail_out;
175 } 186 }
176 } 187 }
177 return 0; 188 return 0;
@@ -180,29 +191,29 @@ Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes )
180Bu::size Bu::BZip2::write( const void *pData, Bu::size nBytes ) 191Bu::size Bu::BZip2::write( const void *pData, Bu::size nBytes )
181{ 192{
182 TRACE( pData, nBytes ); 193 TRACE( pData, nBytes );
183 if( !bzState.state ) 194 if( !pState->state )
184 { 195 {
185 bReading = false; 196 bReading = false;
186 BZ2_bzCompressInit( &bzState, nCompression, 0, 30 ); 197 BZ2_bzCompressInit( pState, nCompression, 0, 30 );
187 } 198 }
188 if( bReading == true ) 199 if( bReading == true )
189 throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); 200 throw ExceptionBase("This bzip2 filter is in reading mode, you can't write.");
190 201
191// Bu::size sTotalOut = 0; 202// Bu::size sTotalOut = 0;
192 bzState.next_in = (char *)pData; 203 pState->next_in = (char *)pData;
193 bzState.avail_in = nBytes; 204 pState->avail_in = nBytes;
194 for(;;) 205 for(;;)
195 { 206 {
196 bzState.avail_out = nBufSize; 207 pState->avail_out = nBufSize;
197 bzState.next_out = pBuf; 208 pState->next_out = pBuf;
198 209
199 bzError( BZ2_bzCompress( &bzState, BZ_RUN ) ); 210 bzError( BZ2_bzCompress( pState, BZ_RUN ) );
200 211
201 if( bzState.avail_out < nBufSize ) 212 if( pState->avail_out < nBufSize )
202 { 213 {
203 sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); 214 sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out );
204 } 215 }
205 if( bzState.avail_in == 0 ) 216 if( pState->avail_in == 0 )
206 break; 217 break;
207 } 218 }
208 219
@@ -212,7 +223,7 @@ Bu::size Bu::BZip2::write( const void *pData, Bu::size nBytes )
212bool Bu::BZip2::isOpen() 223bool Bu::BZip2::isOpen()
213{ 224{
214 TRACE(); 225 TRACE();
215 return (bzState.state != NULL); 226 return (pState->state != NULL);
216} 227}
217 228
218Bu::size Bu::BZip2::getCompressedSize() 229Bu::size Bu::BZip2::getCompressedSize()
diff --git a/src/bzip2.h b/src/bzip2.h
index 6da3dff..0b5140d 100644
--- a/src/bzip2.h
+++ b/src/bzip2.h
@@ -9,7 +9,6 @@
9#define BU_BZIP2_H 9#define BU_BZIP2_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <bzlib.h>
13 12
14#include "bu/filter.h" 13#include "bu/filter.h"
15 14
@@ -36,7 +35,7 @@ namespace Bu
36 35
37 private: 36 private:
38 void bzError( int code ); 37 void bzError( int code );
39 bz_stream bzState; 38 void *prState;
40 bool bReading; 39 bool bReading;
41 int nCompression; 40 int nCompression;
42 char *pBuf; 41 char *pBuf;
diff --git a/src/deflate.cpp b/src/deflate.cpp
index aec2a18..10a9c5f 100644
--- a/src/deflate.cpp
+++ b/src/deflate.cpp
@@ -8,10 +8,15 @@
8#include "bu/deflate.h" 8#include "bu/deflate.h"
9#include "bu/trace.h" 9#include "bu/trace.h"
10 10
11#include <zlib.h>
12
13#define pState ((z_stream *)prState)
14
11using namespace Bu; 15using namespace Bu;
12 16
13Bu::Deflate::Deflate( Bu::Stream &rNext, int nCompression, Format eFmt ) : 17Bu::Deflate::Deflate( Bu::Stream &rNext, int nCompression, Format eFmt ) :
14 Bu::Filter( rNext ), 18 Bu::Filter( rNext ),
19 prState( NULL ),
15 nCompression( nCompression ), 20 nCompression( nCompression ),
16 sTotalOut( 0 ), 21 sTotalOut( 0 ),
17 eFmt( eFmt ), 22 eFmt( eFmt ),
@@ -30,10 +35,11 @@ Bu::Deflate::~Deflate()
30void Bu::Deflate::start() 35void Bu::Deflate::start()
31{ 36{
32 TRACE(); 37 TRACE();
33 zState.zalloc = NULL; 38 prState = new z_stream;
34 zState.zfree = NULL; 39 pState->zalloc = NULL;
35 zState.opaque = NULL; 40 pState->zfree = NULL;
36 zState.state = NULL; 41 pState->opaque = NULL;
42 pState->state = NULL;
37 43
38 nBufSize = 64*1024; 44 nBufSize = 64*1024;
39 pBuf = new char[nBufSize]; 45 pBuf = new char[nBufSize];
@@ -42,34 +48,38 @@ void Bu::Deflate::start()
42Bu::size Bu::Deflate::stop() 48Bu::size Bu::Deflate::stop()
43{ 49{
44 TRACE(); 50 TRACE();
45 if( zState.state ) 51 if( pState && pState->state )
46 { 52 {
47 if( bReading ) 53 if( bReading )
48 { 54 {
49 inflateEnd( &zState ); 55 inflateEnd( pState );
50 delete[] pBuf; 56 delete[] pBuf;
51 pBuf = NULL; 57 pBuf = NULL;
58 delete pState;
59 prState = NULL;
52 return 0; 60 return 0;
53 } 61 }
54 else 62 else
55 { 63 {
56 for(;;) 64 for(;;)
57 { 65 {
58 zState.next_in = NULL; 66 pState->next_in = NULL;
59 zState.avail_in = 0; 67 pState->avail_in = 0;
60 zState.avail_out = nBufSize; 68 pState->avail_out = nBufSize;
61 zState.next_out = (Bytef *)pBuf; 69 pState->next_out = (Bytef *)pBuf;
62 int res = deflate( &zState, Z_FINISH ); 70 int res = deflate( pState, Z_FINISH );
63 if( zState.avail_out < nBufSize ) 71 if( pState->avail_out < nBufSize )
64 { 72 {
65 sTotalOut += rNext.write( pBuf, nBufSize-zState.avail_out ); 73 sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out );
66 } 74 }
67 if( res == Z_STREAM_END ) 75 if( res == Z_STREAM_END )
68 break; 76 break;
69 } 77 }
70 deflateEnd( &zState ); 78 deflateEnd( pState );
71 delete[] pBuf; 79 delete[] pBuf;
72 pBuf = NULL; 80 pBuf = NULL;
81 delete pState;
82 prState = NULL;
73 return sTotalOut; 83 return sTotalOut;
74 } 84 }
75 } 85 }
@@ -87,25 +97,25 @@ void Bu::Deflate::zError( int code )
87 return; 97 return;
88 98
89 case Z_ERRNO: 99 case Z_ERRNO:
90 throw ExceptionBase("Deflate: Errno - %s", zState.msg ); 100 throw ExceptionBase("Deflate: Errno - %s", pState->msg );
91 101
92 case Z_STREAM_ERROR: 102 case Z_STREAM_ERROR:
93 throw ExceptionBase("Deflate: Stream Error - %s", zState.msg ); 103 throw ExceptionBase("Deflate: Stream Error - %s", pState->msg );
94 104
95 case Z_DATA_ERROR: 105 case Z_DATA_ERROR:
96 throw ExceptionBase("Deflate: Data Error - %s", zState.msg ); 106 throw ExceptionBase("Deflate: Data Error - %s", pState->msg );
97 107
98 case Z_MEM_ERROR: 108 case Z_MEM_ERROR:
99 throw ExceptionBase("Deflate: Mem Error - %s", zState.msg ); 109 throw ExceptionBase("Deflate: Mem Error - %s", pState->msg );
100 110
101 case Z_BUF_ERROR: 111 case Z_BUF_ERROR:
102 throw ExceptionBase("Deflate: Buf Error - %s", zState.msg ); 112 throw ExceptionBase("Deflate: Buf Error - %s", pState->msg );
103 113
104 case Z_VERSION_ERROR: 114 case Z_VERSION_ERROR:
105 throw ExceptionBase("Deflate: Version Error - %s", zState.msg ); 115 throw ExceptionBase("Deflate: Version Error - %s", pState->msg );
106 116
107 default: 117 default:
108 throw ExceptionBase("Deflate: Unknown error encountered - %s.", zState.msg ); 118 throw ExceptionBase("Deflate: Unknown error encountered - %s.", pState->msg );
109 119
110 } 120 }
111} 121}
@@ -113,55 +123,55 @@ void Bu::Deflate::zError( int code )
113Bu::size Bu::Deflate::read( void *pData, Bu::size nBytes ) 123Bu::size Bu::Deflate::read( void *pData, Bu::size nBytes )
114{ 124{
115 TRACE( pData, nBytes ); 125 TRACE( pData, nBytes );
116 if( !zState.state ) 126 if( !pState->state )
117 { 127 {
118 bReading = true; 128 bReading = true;
119 if( eFmt&AutoDetect ) 129 if( eFmt&AutoDetect )
120 inflateInit2( &zState, 32+15 ); // Auto-detect, large window 130 inflateInit2( pState, 32+15 ); // Auto-detect, large window
121 else if( eFmt == Raw ) 131 else if( eFmt == Raw )
122 inflateInit2( &zState, -15 ); // Raw 132 inflateInit2( pState, -15 ); // Raw
123 else if( eFmt == Zlib ) 133 else if( eFmt == Zlib )
124 inflateInit2( &zState, 15 ); // Zlib 134 inflateInit2( pState, 15 ); // Zlib
125 else if( eFmt == Gzip ) 135 else if( eFmt == Gzip )
126 inflateInit2( &zState, 16+15 ); // GZip 136 inflateInit2( pState, 16+15 ); // GZip
127 else 137 else
128 throw Bu::ExceptionBase("Format mode for deflate read."); 138 throw Bu::ExceptionBase("Format mode for deflate read.");
129 zState.next_in = (Bytef *)pBuf; 139 pState->next_in = (Bytef *)pBuf;
130 zState.avail_in = 0; 140 pState->avail_in = 0;
131 } 141 }
132 if( bReading == false ) 142 if( bReading == false )
133 throw ExceptionBase("This deflate filter is in writing mode, you can't read."); 143 throw ExceptionBase("This deflate filter is in writing mode, you can't read.");
134 144
135 int nRead = 0; 145 int nRead = 0;
136 int nReadTotal = zState.total_out; 146 int nReadTotal = pState->total_out;
137 zState.next_out = (Bytef *)pData; 147 pState->next_out = (Bytef *)pData;
138 zState.avail_out = nBytes; 148 pState->avail_out = nBytes;
139 for(;;) 149 for(;;)
140 { 150 {
141 int ret = inflate( &zState, Z_NO_FLUSH ); 151 int ret = inflate( pState, Z_NO_FLUSH );
142 printf("inflate returned %d; avail in=%d, out=%d\n", ret, 152 printf("inflate returned %d; avail in=%d, out=%d\n", ret,
143 zState.avail_in, zState.avail_out ); 153 pState->avail_in, pState->avail_out );
144 154
145 nReadTotal += nRead-zState.avail_out; 155 nReadTotal += nRead-pState->avail_out;
146 156
147 if( ret == Z_STREAM_END ) 157 if( ret == Z_STREAM_END )
148 { 158 {
149 bEos = true; 159 bEos = true;
150 if( zState.avail_in > 0 ) 160 if( pState->avail_in > 0 )
151 { 161 {
152 if( rNext.isSeekable() ) 162 if( rNext.isSeekable() )
153 { 163 {
154 rNext.seek( -zState.avail_in ); 164 rNext.seek( -pState->avail_in );
155 } 165 }
156 } 166 }
157 return nBytes-zState.avail_out; 167 return nBytes-pState->avail_out;
158 } 168 }
159 if( ret != Z_BUF_ERROR ) 169 if( ret != Z_BUF_ERROR )
160 zError( ret ); 170 zError( ret );
161 171
162 if( zState.avail_out ) 172 if( pState->avail_out )
163 { 173 {
164 if( zState.avail_in == 0 ) 174 if( pState->avail_in == 0 )
165 { 175 {
166 nRead = rNext.read( pBuf, nBufSize ); 176 nRead = rNext.read( pBuf, nBufSize );
167 if( nRead == 0 && rNext.isEos() ) 177 if( nRead == 0 && rNext.isEos() )
@@ -169,13 +179,13 @@ Bu::size Bu::Deflate::read( void *pData, Bu::size nBytes )
169 throw Bu::ExceptionBase("Premature end of underlying " 179 throw Bu::ExceptionBase("Premature end of underlying "
170 "stream found reading deflate stream."); 180 "stream found reading deflate stream.");
171 } 181 }
172 zState.next_in = (Bytef *)pBuf; 182 pState->next_in = (Bytef *)pBuf;
173 zState.avail_in = nRead; 183 pState->avail_in = nRead;
174 } 184 }
175 } 185 }
176 else 186 else
177 { 187 {
178 return nBytes-zState.avail_out; 188 return nBytes-pState->avail_out;
179 } 189 }
180 } 190 }
181 return 0; 191 return 0;
@@ -184,18 +194,18 @@ Bu::size Bu::Deflate::read( void *pData, Bu::size nBytes )
184Bu::size Bu::Deflate::write( const void *pData, Bu::size nBytes ) 194Bu::size Bu::Deflate::write( const void *pData, Bu::size nBytes )
185{ 195{
186 TRACE( pData, nBytes ); 196 TRACE( pData, nBytes );
187 if( !zState.state ) 197 if( !pState->state )
188 { 198 {
189 bReading = false; 199 bReading = false;
190 int iFmt = eFmt&Gzip; 200 int iFmt = eFmt&Gzip;
191 if( iFmt == Raw ) 201 if( iFmt == Raw )
192 deflateInit2( &zState, nCompression, Z_DEFLATED, -15, 9, 202 deflateInit2( pState, nCompression, Z_DEFLATED, -15, 9,
193 Z_DEFAULT_STRATEGY ); 203 Z_DEFAULT_STRATEGY );
194 else if( iFmt == Zlib ) 204 else if( iFmt == Zlib )
195 deflateInit2( &zState, nCompression, Z_DEFLATED, 15, 9, 205 deflateInit2( pState, nCompression, Z_DEFLATED, 15, 9,
196 Z_DEFAULT_STRATEGY ); 206 Z_DEFAULT_STRATEGY );
197 else if( iFmt == Gzip ) 207 else if( iFmt == Gzip )
198 deflateInit2( &zState, nCompression, Z_DEFLATED, 16+15, 9, 208 deflateInit2( pState, nCompression, Z_DEFLATED, 16+15, 9,
199 Z_DEFAULT_STRATEGY ); 209 Z_DEFAULT_STRATEGY );
200 else 210 else
201 throw Bu::ExceptionBase("Invalid format for deflate."); 211 throw Bu::ExceptionBase("Invalid format for deflate.");
@@ -203,20 +213,20 @@ Bu::size Bu::Deflate::write( const void *pData, Bu::size nBytes )
203 if( bReading == true ) 213 if( bReading == true )
204 throw ExceptionBase("This deflate filter is in reading mode, you can't write."); 214 throw ExceptionBase("This deflate filter is in reading mode, you can't write.");
205 215
206 zState.next_in = (Bytef *)pData; 216 pState->next_in = (Bytef *)pData;
207 zState.avail_in = nBytes; 217 pState->avail_in = nBytes;
208 for(;;) 218 for(;;)
209 { 219 {
210 zState.avail_out = nBufSize; 220 pState->avail_out = nBufSize;
211 zState.next_out = (Bytef *)pBuf; 221 pState->next_out = (Bytef *)pBuf;
212 222
213 zError( deflate( &zState, Z_NO_FLUSH ) ); 223 zError( deflate( pState, Z_NO_FLUSH ) );
214 224
215 if( zState.avail_out < nBufSize ) 225 if( pState->avail_out < nBufSize )
216 { 226 {
217 sTotalOut += rNext.write( pBuf, nBufSize-zState.avail_out ); 227 sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out );
218 } 228 }
219 if( zState.avail_in == 0 ) 229 if( pState->avail_in == 0 )
220 break; 230 break;
221 } 231 }
222 232
@@ -226,7 +236,7 @@ Bu::size Bu::Deflate::write( const void *pData, Bu::size nBytes )
226bool Bu::Deflate::isOpen() 236bool Bu::Deflate::isOpen()
227{ 237{
228 TRACE(); 238 TRACE();
229 return (zState.state != NULL); 239 return (pState != NULL && pState->state != NULL);
230} 240}
231 241
232bool Bu::Deflate::isEos() 242bool Bu::Deflate::isEos()
diff --git a/src/deflate.h b/src/deflate.h
index 8ce283b..20d609a 100644
--- a/src/deflate.h
+++ b/src/deflate.h
@@ -9,7 +9,6 @@
9#define BU_DEFLATE_H 9#define BU_DEFLATE_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <zlib.h>
13 12
14#include "bu/filter.h" 13#include "bu/filter.h"
15 14
@@ -49,7 +48,7 @@ namespace Bu
49 48
50 private: 49 private:
51 void zError( int code ); 50 void zError( int code );
52 z_stream zState; 51 void *prState;
53 bool bReading; 52 bool bReading;
54 int nCompression; 53 int nCompression;
55 char *pBuf; 54 char *pBuf;