X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0915d0b2e210701353ef30743d0df9c195f76295..2654f7e423bb773ca52c8b465c6ec9abfa398e45:/src/common/zstream.cpp diff --git a/src/common/zstream.cpp b/src/common/zstream.cpp index c9d2b701c5..5372d21481 100644 --- a/src/common/zstream.cpp +++ b/src/common/zstream.cpp @@ -38,11 +38,7 @@ #endif enum { -#ifdef __WIN16__ - ZSTREAM_BUFFER_SIZE = 4096 -#else ZSTREAM_BUFFER_SIZE = 16384 -#endif }; ////////////////////// @@ -61,14 +57,19 @@ wxZlibInputStream::wxZlibInputStream(wxInputStream& stream, int flags) m_inflate = new z_stream_s; if (m_inflate) { - m_inflate->zalloc = (alloc_func)0; - m_inflate->zfree = (free_func)0; - m_inflate->opaque = (voidpf)0; - m_inflate->avail_in = 0; - m_inflate->next_in = NULL; - m_inflate->next_out = NULL; + memset(m_inflate, 0, sizeof(z_stream_s)); + + wxASSERT((flags & ~(wxZLIB_ZLIB | wxZLIB_GZIP)) == 0); + + // when autodetecting between gzip & zlib, silently drop gzip flag + // if the version of zlib doesn't support it + if (flags == (wxZLIB_ZLIB | wxZLIB_GZIP) + && strcmp(zlib_version, "1.2.") < 0) + flags &= ~wxZLIB_GZIP; - int bits = (flags & wxZLIB_NO_HEADER) ? -MAX_WBITS : MAX_WBITS; + int bits = flags ? MAX_WBITS : -MAX_WBITS; + if (flags & wxZLIB_GZIP) + bits |= (flags & wxZLIB_ZLIB) ? 0x20 : 0x10; if (inflateInit2(m_inflate, bits) == Z_OK) return; @@ -126,7 +127,10 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size) } m_lasterror = wxSTREAM_EOF; } else if (err != Z_OK) { - wxLogError(_("Can't read from inflate stream (zlib error %d)."), err); + wxString msg(m_inflate->msg, *wxConvCurrent); + if (!msg) + msg.Format(_("zlib error %d"), err); + wxLogError(_("Can't read from inflate stream: %s\n"), msg.c_str()); m_lasterror = wxSTREAM_READ_ERROR; } @@ -162,14 +166,15 @@ wxZlibOutputStream::wxZlibOutputStream(wxOutputStream& stream, m_deflate = new z_stream_s; if (m_deflate) { - m_deflate->zalloc = (alloc_func)0; - m_deflate->zfree = (free_func)0; - m_deflate->opaque = (voidpf)0; - m_deflate->avail_in = 0; + memset(m_deflate, 0, sizeof(z_stream_s)); m_deflate->next_out = m_z_buffer; m_deflate->avail_out = m_z_size; - int bits = (flags & wxZLIB_NO_HEADER) ? -MAX_WBITS : MAX_WBITS; + wxASSERT(flags == 0 || flags == wxZLIB_ZLIB || flags == wxZLIB_GZIP); + + int bits = flags ? MAX_WBITS : -MAX_WBITS; + if (flags & wxZLIB_GZIP) + bits |= 0x10; if (deflateInit2(m_deflate, level, Z_DEFLATED, bits, 8, Z_DEFAULT_STRATEGY) == Z_OK) @@ -253,7 +258,10 @@ size_t wxZlibOutputStream::OnSysWrite(const void *buffer, size_t size) if (err != Z_OK) { m_lasterror = wxSTREAM_WRITE_ERROR; - wxLogError(_("Can't write to deflate stream (zlib error %d)."), err); + wxString msg(m_deflate->msg, *wxConvCurrent); + if (!msg) + msg.Format(_("zlib error %d"), err); + wxLogError(_("Can't write to deflate stream: %s\n"), msg.c_str()); } size -= m_deflate->avail_in;