15 #include "compressionzlib.h"
30 m_zinflate.zalloc = Z_NULL;
31 m_zinflate.zfree = Z_NULL;
32 m_zinflate.opaque = Z_NULL;
33 m_zinflate.avail_in = 0;
34 m_zinflate.next_in = Z_NULL;
35 ret = inflateInit( &m_zinflate );
39 m_zdeflate.zalloc = Z_NULL;
40 m_zdeflate.zfree = Z_NULL;
41 m_zdeflate.opaque = Z_NULL;
42 m_zinflate.avail_in = 0;
43 m_zinflate.next_in = Z_NULL;
44 ret = deflateInit( &m_zdeflate, Z_BEST_COMPRESSION );
65 long unsigned int CHUNK = data.length() + ( data.length() / 100 ) + 13;
66 Bytef* out =
new Bytef[CHUNK];
67 char* in =
const_cast<char*
>( data.c_str() );
69 m_compressMutex.
lock();
71 m_zdeflate.avail_in =
static_cast<uInt
>( data.length() );
72 m_zdeflate.next_in =
reinterpret_cast<Bytef*
>( in );
76 m_zdeflate.avail_out =
static_cast<uInt
>( CHUNK );
77 m_zdeflate.next_out =
reinterpret_cast<Bytef*
>( out );
79 deflate( &m_zdeflate, Z_SYNC_FLUSH );
80 result.append(
reinterpret_cast<char*
>( out ), CHUNK - m_zdeflate.avail_out );
81 }
while( m_zdeflate.avail_out == 0 );
99 char* out =
new char[CHUNK];
100 char* in =
const_cast<char*
>( data.c_str() );
102 m_zinflate.avail_in =
static_cast<uInt
>( data.length() );
103 m_zinflate.next_in =
reinterpret_cast<Bytef*
>( in );
108 m_zinflate.avail_out = CHUNK;
109 m_zinflate.next_out =
reinterpret_cast<Bytef*
>( out );
111 inflate( &m_zinflate, Z_SYNC_FLUSH );
112 result.append( out, CHUNK - m_zinflate.avail_out );
113 }
while( m_zinflate.avail_out == 0 );
122 m_compressMutex.
lock();
126 inflateEnd( &m_zinflate );
127 deflateEnd( &m_zdeflate );
This is an abstract base class for stream compression implementations.
CompressionDataHandler * m_handler
An abstract base class used to receive de/compressed data from a CompressionBase-derived object.
virtual void handleCompressedData(const std::string &data)=0
virtual void handleDecompressedData(const std::string &data)=0
virtual ~CompressionZlib()
CompressionZlib(CompressionDataHandler *cdh)
virtual void compress(const std::string &data)
virtual void decompress(const std::string &data)
The namespace for the gloox library.