- m_parent_o_stream->Write(m_z_buffer, m_z_size-m_deflate->avail_out);
- m_deflate->next_out = m_z_buffer;
- m_deflate->avail_out = m_z_size;
+ while (err == Z_OK || err == Z_STREAM_END) {
+ size_t len = m_z_size - m_deflate->avail_out;
+ if (len) {
+ if (m_parent_o_stream->Write(m_z_buffer, len).LastWrite() != len) {
+ m_lasterror = wxSTREAM_WRITE_ERROR;
+ wxLogDebug(wxT("wxZlibOutputStream: Error writing to underlying stream"));
+ break;
+ }
+ m_deflate->next_out = m_z_buffer;
+ m_deflate->avail_out = m_z_size;
+ }
+
+ if (done)
+ break;
+ err = deflate(m_deflate, final ? Z_FINISH : Z_FULL_FLUSH);
+ done = m_deflate->avail_out != 0 || err == Z_STREAM_END;
+ }