30 size_t compress(
const void* src,
size_t src_len,
void* dest,
size_t dest_len) {
32 info.avail_in = src_len;
33 info.avail_out = dest_len;
34 info.next_in = (Bytef*)src;
35 info.next_out = (Bytef*)dest;
36 info.data_type = Z_BINARY;
38 int r = deflateInit(&info, Z_DEFAULT_COMPRESSION);
40 r = deflate(&info, Z_FINISH);
41 if(r == Z_STREAM_END) {
43 return info.total_out;
46 CXX_THROW(std::runtime_error,
"Insufficient zlib output buffer size for deflate");
49 size_t decompress(
const void* src,
size_t src_len,
void* dest,
size_t dest_len) {
51 info.avail_in = src_len;
52 info.avail_out = dest_len;
53 info.next_in = (Bytef*)src;
54 info.next_out = (Bytef*)dest;
55 info.data_type = Z_BINARY;
57 int r = inflateInit(&info);
59 r = inflate(&info, Z_FINISH);
60 if(r == Z_STREAM_END) {
62 return info.total_out;
65 CXX_THROW(std::runtime_error,
"Insufficient zlib output buffer size for inflate");
size_t decompress(const void *src, size_t src_len, void *dest, size_t dest_len)
size_t compress(const void *src, size_t src_len, void *dest, size_t dest_len)
#define CXX_THROW(class,...)