- 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;
-
- 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 ? MAX_WBITS : -MAX_WBITS;
- if (flags & wxZLIB_GZIP)
- bits |= (flags & wxZLIB_ZLIB) ? 0x20 : 0x10;
-
- if (inflateInit2(m_inflate, bits) == Z_OK)
+ memset(m_inflate, 0, sizeof(z_stream_s));
+
+ // see zlib.h for documentation on windowBits
+ int windowBits = MAX_WBITS;
+ switch (flags) {
+ case wxZLIB_NO_HEADER: windowBits = -MAX_WBITS; break;
+ case wxZLIB_ZLIB: windowBits = MAX_WBITS; break;
+ case wxZLIB_GZIP: windowBits = MAX_WBITS | ZSTREAM_GZIP; break;
+ case wxZLIB_AUTO: windowBits = MAX_WBITS | ZSTREAM_AUTO; break;
+ default: wxFAIL_MSG(wxT("Invalid zlib flag"));
+ }
+
+ if (inflateInit2(m_inflate, windowBits) == Z_OK)