1 /*
2 * Zlib Compressor
3 * (C) 2001 Peter J Jones
4 *     2001-2007 Jack Lloyd
5 *
6 * Distributed under the terms of the Botan license
7 */
8 
9 #ifndef BOTAN_ZLIB_H__
10 #define BOTAN_ZLIB_H__
11 
12 #include <botan/filter.h>
13 
14 namespace Botan {
15 
16 /**
17 * Zlib Compression Filter
18 */
19 class BOTAN_DLL Zlib_Compression : public Filter
20    {
21    public:
name()22       std::string name() const { return "Zlib_Compression"; }
23 
24       void write(const byte input[], size_t length);
25       void start_msg();
26       void end_msg();
27 
28       /**
29       * Flush the compressor
30       */
31       void flush();
32 
33       /**
34       @param level how much effort to use on compressing (0 to 9);
35       higher levels are slower but tend to give better compression
36       */
37       Zlib_Compression(size_t level = 6);
38 
~Zlib_Compression()39       ~Zlib_Compression() { clear(); }
40    private:
41       void clear();
42       const size_t level;
43       SecureVector<byte> buffer;
44       class Zlib_Stream* zlib;
45    };
46 
47 /**
48 * Zlib Decompression Filter
49 */
50 class BOTAN_DLL Zlib_Decompression : public Filter
51    {
52    public:
name()53       std::string name() const { return "Zlib_Decompression"; }
54 
55       void write(const byte input[], size_t length);
56       void start_msg();
57       void end_msg();
58 
59       Zlib_Decompression();
~Zlib_Decompression()60       ~Zlib_Decompression() { clear(); }
61    private:
62       void clear();
63       SecureVector<byte> buffer;
64       class Zlib_Stream* zlib;
65       bool no_writes;
66    };
67 
68 }
69 
70 #endif
71