[ci] Enable IRC notifications from travis
[xapian.git] / xapian-core / common / compression_stream.h
blob6c6c2d33fee3c73d6939295065929e2b18182a9a
1 /** @file compression_stream.h
2 * @brief class wrapper around zlib
3 */
4 /* Copyright (C) 2012 Dan Colish
5 * Copyright (C) 2012,2013,2014,2016 Olly Betts
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef XAPIAN_INCLUDED_COMPRESSION_STREAM_H
23 #define XAPIAN_INCLUDED_COMPRESSION_STREAM_H
25 #include "internaltypes.h"
26 #include <string>
27 #include <zlib.h>
29 class CompressionStream {
30 int compress_strategy;
32 size_t out_len;
34 char* out;
36 /// Zlib state object for deflating
37 z_stream* deflate_zstream;
39 /// Zlib state object for inflating
40 z_stream* inflate_zstream;
42 /// Allocate the zstream for deflating, if not already allocated.
43 void lazy_alloc_deflate_zstream();
45 /// Allocate the zstream for inflating, if not already allocated.
46 void lazy_alloc_inflate_zstream();
48 public:
49 /* Create a new CompressionStream object.
51 * @param compress_strategy_ Z_DEFAULT_STRATEGY,
52 * Z_FILTERED, Z_HUFFMAN_ONLY, or Z_RLE.
54 explicit CompressionStream(int compress_strategy_ = Z_DEFAULT_STRATEGY)
55 : compress_strategy(compress_strategy_),
56 out_len(0),
57 out(NULL),
58 deflate_zstream(NULL),
59 inflate_zstream(NULL)
60 { }
62 ~CompressionStream();
64 const char* compress(const char* buf, size_t* p_size);
66 void decompress_start() { lazy_alloc_inflate_zstream(); }
68 /** Returns true if this was the final chunk. */
69 bool decompress_chunk(const char* p, int len, std::string& buf);
72 #endif // XAPIAN_INCLUDED_COMPRESSION_STREAM_H