11 #if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
13 #include <Atlas/Filters/Gzip.h>
17 #define ASSERT(exp) assert(exp)
22 const int DEFAULT_LEVEL = 6;
26 incoming.next_in = Z_NULL;
27 incoming.avail_in = 0;
28 incoming.zalloc = Z_NULL;
29 incoming.zfree = Z_NULL;
31 outgoing.zalloc = Z_NULL;
32 outgoing.zfree = Z_NULL;
34 inflateInit(&incoming);
35 deflateInit(&outgoing, DEFAULT_LEVEL);
40 inflateEnd(&incoming);
41 deflateEnd(&outgoing);
44 std::string Gzip::encode(
const std::string& data)
46 std::string out_string;
52 #if ZLIB_VERNUM < 0x1252
53 outgoing.next_in = (
unsigned char *)data.data();
55 outgoing.next_in = (z_const Bytef*)data.data();
57 outgoing.avail_in = data.size();
61 outgoing.next_out = buf;
62 outgoing.avail_out =
sizeof(buf);
64 status = deflate(&outgoing, Z_SYNC_FLUSH);
66 ASSERT(status == Z_OK);
69 out_string.append((
char*)buf,
sizeof(buf) - outgoing.avail_out);
71 }
while (outgoing.avail_out == 0);
76 std::string Gzip::decode(
const std::string& data)
78 std::string out_string;
83 #if ZLIB_VERNUM < 0x1252
84 incoming.next_in = (
unsigned char *)data.data();
86 incoming.next_in = (z_const Bytef*)data.data();
88 incoming.avail_in = data.size();
92 incoming.next_out = buf;
93 incoming.avail_out =
sizeof(buf);
95 int status = inflate(&incoming, Z_SYNC_FLUSH);
97 ASSERT(status == Z_OK);
100 out_string.append((
char*)buf,
sizeof(buf) - incoming.avail_out);
102 }
while(incoming.avail_out == 0);