2323
2424#if HAVE_ZLIB
2525#include < zlib.h>
26+ #define DFLT_WINDOWS_BIT (-MAX_WBITS )
27+ #define GZIP_WINDOWS_BIT ((MAX_WBITS )+16 )
28+ #define GZIP_CHUNK_SIZE 16384
2629#else
27- #define Z_NO_FLUSH 0
28- #define Z_OK 0
29- #define Z_STREAM_END 1
30- #define Z_STREAM_ERROR (-2 )
31- #define Z_BUF_ERROR (-5 )
30+ #define Z_NO_FLUSH 0
31+ #define Z_OK 0
32+ #define Z_STREAM_END 1
33+ #define Z_STREAM_ERROR (-2 )
34+ #define Z_BUF_ERROR (-5 )
35+ #define DFLT_WINDOWS_BIT 0
36+ #define GZIP_WINDOWS_BIT 0
37+ #define GZIP_CHUNK_SIZE 0
3238#endif
3339
34- #define GZIP_WINDOWS_BIT 15 + 16
35- #define GZIP_CHUNK_SIZE 16384
3640#define MIN (a,b ) (a > b ? b : a)
3741#define MAX (a,b ) (a > b ? a : b)
3842
3943using namespace NSROOT ;
4044
41- Compressor::Compressor (const char *input, size_t len, int level /* = -1*/ )
45+ Compressor::Compressor (const char *input, size_t len, bool gzip, int level /* = -1*/ )
4246: m_status(Z_STREAM_ERROR )
4347, m_flush(Z_NO_FLUSH )
4448, m_stop(true )
@@ -57,12 +61,14 @@ Compressor::Compressor(const char *input, size_t len, int level /*= -1*/)
5761#if HAVE_ZLIB
5862 m_output = new char [m_chunk_size];
5963 _opaque = new z_stream;
60- m_status = _init (_opaque, m_output, m_chunk_size, level);
64+ m_status = _init (_opaque, m_output, m_chunk_size,
65+ (gzip ? GZIP_WINDOWS_BIT : DFLT_WINDOWS_BIT ),
66+ level);
6167 m_stop = (m_status != Z_OK );
6268#endif
6369}
6470
65- Compressor::Compressor (STREAM_READER reader, void *handle, int level /* = -1*/ )
71+ Compressor::Compressor (STREAM_READER reader, void *handle, bool gzip, int level /* = -1*/ )
6672: m_status(Z_STREAM_ERROR )
6773, m_flush(Z_NO_FLUSH )
6874, m_stop(true )
@@ -82,7 +88,9 @@ Compressor::Compressor(STREAM_READER reader, void *handle, int level /*= -1*/)
8288 m_rstream_buf = new char [m_chunk_size];
8389 m_output = new char [m_chunk_size];
8490 _opaque = new z_stream;
85- m_status = _init (_opaque, m_output, m_chunk_size, level);
91+ m_status = _init (_opaque, m_output, m_chunk_size,
92+ (gzip ? GZIP_WINDOWS_BIT : DFLT_WINDOWS_BIT ),
93+ level);
8694 m_stop = (m_status != Z_OK );
8795#endif
8896}
@@ -219,7 +227,7 @@ size_t Compressor::FetchOutput(const char **data)
219227 return 0 ;
220228}
221229
222- int Compressor::_init (void *zp, void *out, size_t len, int level)
230+ int Compressor::_init (void *zp, void *out, size_t len, int wbits, int level)
223231{
224232#if HAVE_ZLIB
225233 z_stream *strm = static_cast <z_stream*>(zp);
@@ -231,7 +239,7 @@ int Compressor::_init(void *zp, void *out, size_t len, int level)
231239 strm->next_in = Z_NULL ;
232240 strm->avail_out = len;
233241 strm->next_out = (unsigned char *)out;
234- return deflateInit2 (strm, MAX (-1 , MIN (level, 9 )), Z_DEFLATED , GZIP_WINDOWS_BIT , 8 , Z_DEFAULT_STRATEGY );
242+ return deflateInit2 (strm, MAX (-1 , MIN (level, 9 )), Z_DEFLATED , wbits , 8 , Z_DEFAULT_STRATEGY );
235243#else
236244 return Z_STREAM_ERROR ;
237245#endif
@@ -285,7 +293,7 @@ size_t Compressor::NextChunk()
285293 return sz;
286294}
287295
288- Decompressor::Decompressor (const char *input, size_t len)
296+ Decompressor::Decompressor (const char *input, size_t len, bool gzip )
289297: m_status(Z_STREAM_ERROR )
290298, m_stop(true )
291299, m_chunk_size(GZIP_CHUNK_SIZE )
@@ -303,12 +311,13 @@ Decompressor::Decompressor(const char *input, size_t len)
303311#if HAVE_ZLIB
304312 m_output = new char [m_chunk_size];
305313 _opaque = new z_stream;
306- m_status = _init (_opaque, m_output, m_chunk_size);
314+ m_status = _init (_opaque, m_output, m_chunk_size,
315+ (gzip ? GZIP_WINDOWS_BIT : DFLT_WINDOWS_BIT ));
307316 m_stop = (m_status != Z_OK );
308317#endif
309318}
310319
311- Decompressor::Decompressor (STREAM_READER reader, void *handle)
320+ Decompressor::Decompressor (STREAM_READER reader, void *handle, bool gzip )
312321: m_status(Z_STREAM_ERROR )
313322, m_stop(true )
314323, m_chunk_size(GZIP_CHUNK_SIZE )
@@ -327,7 +336,8 @@ Decompressor::Decompressor(STREAM_READER reader, void *handle)
327336 m_rstream_buf = new char [m_chunk_size];
328337 m_output = new char [m_chunk_size];
329338 _opaque = new z_stream;
330- m_status = _init (_opaque, m_output, m_chunk_size);
339+ m_status = _init (_opaque, m_output, m_chunk_size,
340+ (gzip ? GZIP_WINDOWS_BIT : DFLT_WINDOWS_BIT ));
331341 m_stop = (m_status != Z_OK );
332342#endif
333343}
@@ -464,7 +474,7 @@ size_t Decompressor::FetchOutput(const char **data)
464474 return 0 ;
465475}
466476
467- int Decompressor::_init (void *zp, void *out, size_t len)
477+ int Decompressor::_init (void *zp, void *out, size_t len, int wbits )
468478{
469479#if HAVE_ZLIB
470480 z_stream *strm = static_cast <z_stream*>(zp);
@@ -476,7 +486,7 @@ int Decompressor::_init(void *zp, void *out, size_t len)
476486 strm->next_in = Z_NULL ;
477487 strm->avail_out = len;
478488 strm->next_out = (unsigned char *)out;
479- return inflateInit2 (strm, GZIP_WINDOWS_BIT );
489+ return inflateInit2 (strm, wbits );
480490#else
481491 return Z_STREAM_ERROR ;
482492#endif
0 commit comments