2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Bacula zlib compression wrappers
30 * Deflate or compress and input buffer. You must supply an
31 * output buffer sufficiently long and the length of the
32 * output buffer. Generally, if the output buffer is the
33 * same size as the input buffer, it should work (at least
36 int Zdeflate(char *in, int in_len, char *out, int &out_len)
42 /* allocate deflate state */
46 ret = deflateInit(&strm, 9);
48 Dmsg0(200, "deflateInit error\n");
49 (void)deflateEnd(&strm);
53 strm.next_in = (Bytef *)in;
54 strm.avail_in = in_len;
55 Dmsg1(200, "In: %d bytes\n", strm.avail_in);
56 strm.avail_out = out_len;
57 strm.next_out = (Bytef *)out;
58 ret = deflate(&strm, Z_FINISH);
59 out_len = out_len - strm.avail_out;
60 Dmsg1(200, "compressed=%d\n", out_len);
61 (void)deflateEnd(&strm);
69 * Inflate or uncompress an input buffer. You must supply
70 * and output buffer and an output length sufficiently long
71 * or there will be an error. This uncompresses in one call.
73 int Zinflate(char *in, int in_len, char *out, int &out_len)
79 /* allocate deflate state */
83 strm.next_in = (Bytef *)in;
84 strm.avail_in = in_len;
85 ret = inflateInit(&strm);
87 Dmsg0(200, "inflateInit error\n");
88 (void)inflateEnd(&strm);
92 Dmsg1(200, "In len: %d bytes\n", strm.avail_in);
93 strm.avail_out = out_len;
94 strm.next_out = (Bytef *)out;
95 ret = inflate(&strm, Z_FINISH);
96 out_len -= strm.avail_out;
97 Dmsg1(200, "Uncompressed=%d\n", out_len);
98 (void)inflateEnd(&strm);