2 #include "zipios++/zipios-config.h"
4 #include "zipios++/meta-iostreams.h"
20 _zs_initialized ( false ),
22 _invec ( _invecsize ),
24 _outvec ( _outvecsize )
43 InflateInputStreambuf::~InflateInputStreambuf() {
45 int err = inflateEnd( &_zs ) ;
47 cerr <<
"~inflatebuf: inflateEnd failed" ;
49 cerr <<
": " << zError( err ) ;
56 int InflateInputStreambuf::underflow() {
58 if ( gptr() < egptr() )
59 return static_cast< unsigned char >( *gptr() ) ;
62 _zs.avail_out = _outvecsize ;
63 _zs.next_out =
reinterpret_cast< unsigned char *
>( &( _outvec[ 0 ] ) ) ;
68 while ( _zs.avail_out > 0 && err == Z_OK ) {
69 if ( _zs.avail_in == 0 ) {
70 int bc = _inbuf->sgetn( &(_invec[ 0 ] ) ,
73 _zs.next_in =
reinterpret_cast< unsigned char *
>( &( _invec[0] ) ) ;
81 err = inflate( &_zs, Z_NO_FLUSH ) ;
87 int inflated_bytes = _outvecsize - _zs.avail_out ;
88 setg( &( _outvec[ 0 ] ),
90 &( _outvec[ 0 ] ) + inflated_bytes ) ;
94 if( err != Z_OK && err != Z_STREAM_END ) {
95 #if defined (HAVE_STD_IOSTREAM) && defined (USE_STD_IOSTREAM)
97 OutputStringStream msgs ;
98 msgs <<
"InflateInputStreambuf: inflate failed" ;
100 msgs <<
": " << zError( err ) ;
102 throw IOException( msgs.str() ) ;
107 if (inflated_bytes > 0 )
108 return static_cast< unsigned char >( *gptr() ) ;
118 if ( stream_position >= 0 ) {
119 _inbuf->pubseekpos( stream_position ) ;
124 _zs.next_in =
reinterpret_cast< unsigned char *
>( &( _invec[0] ) ) ;
128 if( _zs_initialized ) {
129 err = inflateReset( &_zs ) ;
131 err = inflateInit2( &_zs, -MAX_WBITS ) ;
138 _zs_initialized = true ;
146 setg( &( _outvec[ 0 ] ),
147 &( _outvec[ 0 ] ) + _outvecsize,
148 &( _outvec[ 0 ] ) + _outvecsize ) ;