| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_ZLIBSTREAM_H ) |
| 23 |
#define INCLUDED_ZLIBSTREAM_H |
| 24 |
|
| 25 |
#include "zlib.h" |
| 26 |
#include "idatastream.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class DeflatedInputStream : public InputStream |
| 33 |
{ |
| 34 |
InputStream& m_istream; |
| 35 |
z_stream m_zipstream; |
| 36 |
enum unnamed0 { m_bufsize = 1024 }; |
| 37 |
unsigned char m_buffer[m_bufsize]; |
| 38 |
|
| 39 |
public: |
| 40 |
DeflatedInputStream( InputStream& istream ) |
| 41 |
: m_istream( istream ){ |
| 42 |
m_zipstream.zalloc = 0; |
| 43 |
m_zipstream.zfree = 0; |
| 44 |
m_zipstream.opaque = 0; |
| 45 |
m_zipstream.avail_in = 0; |
| 46 |
inflateInit2( &m_zipstream, -MAX_WBITS ); |
| 47 |
} |
| 48 |
~DeflatedInputStream(){ |
| 49 |
inflateEnd( &m_zipstream ); |
| 50 |
} |
| 51 |
size_type read( byte_type* buffer, size_type length ){ |
| 52 |
m_zipstream.next_out = buffer; |
| 53 |
m_zipstream.avail_out = static_cast<uInt>( length ); |
| 54 |
while ( m_zipstream.avail_out != 0 ) |
| 55 |
{ |
| 56 |
if ( m_zipstream.avail_in == 0 ) { |
| 57 |
m_zipstream.next_in = m_buffer; |
| 58 |
m_zipstream.avail_in = static_cast<uInt>( m_istream.read( m_buffer, m_bufsize ) ); |
| 59 |
} |
| 60 |
if ( inflate( &m_zipstream, Z_SYNC_FLUSH ) != Z_OK ) { |
| 61 |
break; |
| 62 |
} |
| 63 |
} |
| 64 |
return length - m_zipstream.avail_out; |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
#endif |