15 #include "compressionzlib.h"
26 m_zinflate.zalloc = Z_NULL;
27 m_zinflate.zfree = Z_NULL;
28 m_zinflate.opaque = Z_NULL;
29 m_zinflate.avail_in = 0;
30 m_zinflate.next_in = Z_NULL;
31 ret = inflateInit( &m_zinflate );
35 m_zdeflate.zalloc = Z_NULL;
36 m_zdeflate.zfree = Z_NULL;
37 m_zdeflate.opaque = Z_NULL;
38 m_zinflate.avail_in = 0;
39 m_zinflate.next_in = Z_NULL;
40 ret = deflateInit( &m_zdeflate, Z_BEST_COMPRESSION );
49 inflateEnd( &m_zinflate );
50 deflateEnd( &m_zdeflate );
55 if( !m_valid || !m_handler || data.empty() )
58 m_compressMutex.
lock();
60 int CHUNK = data.length() + ( data.length() / 100 ) + 13;
61 Bytef *out =
new Bytef[CHUNK];
62 char *in =
const_cast<char*
>( data.c_str() );
64 m_zdeflate.avail_in = data.length();
65 m_zdeflate.next_in = (Bytef*)in;
70 m_zdeflate.avail_out = CHUNK;
71 m_zdeflate.next_out = (Bytef*)out;
73 ret = deflate( &m_zdeflate, Z_SYNC_FLUSH );
74 result.append( (
char*)out, CHUNK - m_zdeflate.avail_out );
75 }
while( m_zdeflate.avail_out == 0 );
86 if( !m_valid || !m_handler || data.empty() )
90 char *out =
new char[CHUNK];
91 char *in =
const_cast<char*
>( data.c_str() );
93 m_zinflate.avail_in = data.length();
94 m_zinflate.next_in = (Bytef*)in;
100 m_zinflate.avail_out = CHUNK;
101 m_zinflate.next_out = (Bytef*)out;
103 ret = inflate( &m_zinflate, Z_SYNC_FLUSH );
104 result.append( out, CHUNK - m_zinflate.avail_out );
105 }
while( m_zinflate.avail_out == 0 );