- 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;
- m_deflate->next_out = m_z_buffer;
- m_deflate->avail_out = m_z_size;
-
- int bits = (flags & wxZLIB_NO_HEADER) ? -MAX_WBITS : MAX_WBITS;
-
- if (deflateInit2(m_deflate, level, Z_DEFLATED, bits,
- 8, Z_DEFAULT_STRATEGY) == Z_OK)
- return;
- }
+ m_deflate = new z_stream_s;
+
+ if (m_deflate) {
+ memset(m_deflate, 0, sizeof(z_stream_s));
+ m_deflate->next_out = m_z_buffer;
+ m_deflate->avail_out = m_z_size;
+
+ // 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;
+ default: wxFAIL_MSG(wxT("Invalid zlib flag"));
+ }
+
+ if (deflateInit2(m_deflate, level, Z_DEFLATED, windowBits,
+ 8, Z_DEFAULT_STRATEGY) == Z_OK)
+ return;
+ }