X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=plugins%2Farchivezip%2Fzlibstream.h;h=5e2b2096251e347f8f434d5ccd2163a790f5c988;hb=9dfae1c9b270ee369c6362903a9205b30751b95f;hp=2e2e7d8f47fb7917a861f8ee9c93eab3631225d0;hpb=dac8329952745dbb494bad1c301e44bab05ec0db;p=xonotic%2Fnetradiant.git diff --git a/plugins/archivezip/zlibstream.h b/plugins/archivezip/zlibstream.h index 2e2e7d8f..5e2b2096 100644 --- a/plugins/archivezip/zlibstream.h +++ b/plugins/archivezip/zlibstream.h @@ -29,40 +29,43 @@ /// /// - Uses z_stream to decompress the data stream on the fly. /// - Uses a buffer to reduce the number of times the wrapped stream must be read. -class DeflatedInputStream : public InputStream -{ -InputStream& m_istream; -z_stream m_zipstream; -enum unnamed0 { m_bufsize = 1024 }; -unsigned char m_buffer[m_bufsize]; +class DeflatedInputStream : public InputStream { + InputStream &m_istream; + z_stream m_zipstream; + enum unnamed0 { m_bufsize = 1024 }; + unsigned char m_buffer[m_bufsize]; public: -DeflatedInputStream( InputStream& istream ) - : m_istream( istream ){ - m_zipstream.zalloc = 0; - m_zipstream.zfree = 0; - m_zipstream.opaque = 0; - m_zipstream.avail_in = 0; - inflateInit2( &m_zipstream, -MAX_WBITS ); -} -~DeflatedInputStream(){ - inflateEnd( &m_zipstream ); -} -size_type read( byte_type* buffer, size_type length ){ - m_zipstream.next_out = buffer; - m_zipstream.avail_out = static_cast( length ); - while ( m_zipstream.avail_out != 0 ) - { - if ( m_zipstream.avail_in == 0 ) { - m_zipstream.next_in = m_buffer; - m_zipstream.avail_in = static_cast( m_istream.read( m_buffer, m_bufsize ) ); - } - if ( inflate( &m_zipstream, Z_SYNC_FLUSH ) != Z_OK ) { - break; - } - } - return length - m_zipstream.avail_out; -} + DeflatedInputStream(InputStream &istream) + : m_istream(istream) + { + m_zipstream.zalloc = 0; + m_zipstream.zfree = 0; + m_zipstream.opaque = 0; + m_zipstream.avail_in = 0; + inflateInit2(&m_zipstream, -MAX_WBITS); + } + + ~DeflatedInputStream() + { + inflateEnd(&m_zipstream); + } + + size_type read(byte_type *buffer, size_type length) + { + m_zipstream.next_out = buffer; + m_zipstream.avail_out = static_cast( length ); + while (m_zipstream.avail_out != 0) { + if (m_zipstream.avail_in == 0) { + m_zipstream.next_in = m_buffer; + m_zipstream.avail_in = static_cast( m_istream.read(m_buffer, m_bufsize)); + } + if (inflate(&m_zipstream, Z_SYNC_FLUSH) != Z_OK) { + break; + } + } + return length - m_zipstream.avail_out; + } }; #endif