1 #include "ZlibCompressor.h"
4 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 ZlibCompressor::ZlibCompressor (
9 ::Compression::CompressorFactory_ptr compressor_factory
,
10 ::Compression::CompressionLevel compression_level
) :
11 BaseCompressor (compressor_factory
, compression_level
)
16 ZlibCompressor::compress (
17 const ::Compression::Buffer
& source
,
18 ::Compression::Buffer
& target
)
20 // Ensure maximum is at least a bit bigger than input length.
21 target
.length(static_cast<CORBA::ULong
>((source
.length() * 1.001) + 12));
23 uLongf max_length
= static_cast <uLongf
>(target
.maximum());
25 int const retval
= ::compress2 (reinterpret_cast <Bytef
*>(target
.get_buffer ()),
27 reinterpret_cast <const Bytef
*>(source
.get_buffer ()),
29 this->compression_level ());
33 throw ::Compression::CompressionException (retval
, ::zError (retval
));
37 target
.length (static_cast <CORBA::ULong
> (max_length
));
40 // Update statistics for this compressor
41 this->update_stats (source
.length (), target
.length ());
45 ZlibCompressor::decompress (
46 const ::Compression::Buffer
& source
,
47 ::Compression::Buffer
& target
)
49 uLongf max_length
= static_cast <uLongf
> (target
.maximum ());
50 int const retval
= uncompress (reinterpret_cast <Bytef
*>(target
.get_buffer ()),
52 reinterpret_cast <const Bytef
*>(source
.get_buffer ()),
57 throw ::Compression::CompressionException (retval
, "");
61 target
.length (static_cast <CORBA::ULong
> (max_length
));
66 TAO_END_VERSIONED_NAMESPACE_DECL