+ wxASSERT_MSG(m_inflate && m_z_buffer, wxT("Inflate stream not open"));
+
+ if (!m_inflate || !m_z_buffer)
+ m_lasterror = wxSTREAM_READ_ERROR;
+ if (!IsOk() || !size)
+ return 0;
+
+ int err = Z_OK;
+ m_inflate->next_out = (unsigned char *)buffer;
+ m_inflate->avail_out = size;
+
+ while (err == Z_OK && m_inflate->avail_out > 0) {
+ if (m_inflate->avail_in == 0 && m_parent_i_stream->IsOk()) {
+ m_parent_i_stream->Read(m_z_buffer, m_z_size);
+ m_inflate->next_in = m_z_buffer;
+ m_inflate->avail_in = m_parent_i_stream->LastRead();
+ }
+ err = inflate(m_inflate, Z_SYNC_FLUSH);
+ }
+
+ switch (err) {
+ case Z_OK:
+ break;
+
+ case Z_STREAM_END:
+ // Unread any data taken from past the end of the deflate stream, so that
+ // any additional data can be read from the underlying stream (the crc
+ // in a gzip for example)
+ if (m_inflate->avail_in) {
+ m_parent_i_stream->Ungetch(m_inflate->next_in, m_inflate->avail_in);
+ m_inflate->avail_in = 0;
+ }
+ m_lasterror = wxSTREAM_EOF;
+ break;
+
+ case Z_BUF_ERROR:
+ // Indicates that zlib was expecting more data, but the parent stream
+ // has none. Other than Eof the error will have been already reported
+ // by the parent strean,
+ m_lasterror = wxSTREAM_READ_ERROR;
+ if (m_parent_i_stream->Eof())
+#if WXWIN_COMPATIBILITY_2_4
+ if (m_24compatibilty)
+ m_lasterror = wxSTREAM_EOF;
+ else
+#endif
+ wxLogError(_("Can't read inflate stream: unexpected EOF in underlying stream."));
+ break;
+
+ default:
+ wxString msg(m_inflate->msg, *wxConvCurrent);
+ if (!msg)
+ msg.Format(_("zlib error %d"), err);
+ wxLogError(_("Can't read from inflate stream: %s"), msg.c_str());
+ m_lasterror = wxSTREAM_READ_ERROR;
+ }
+
+ size -= m_inflate->avail_out;
+ m_pos += size;
+ return size;