Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / include / wvgzip.h
blob6aed7bdf38a527ee011703040f0c0fb9e21793e4
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Gzip encoder/decoder based on zlib.
6 */
7 #ifndef __WVGZIP_H
8 #define __WVGZIP_H
10 #include "wvencoder.h"
11 #include "wvencoderstream.h"
13 struct z_stream_s;
15 /**
16 * An encoder implementing Gzip encryption and decryption.
18 * When compressing:
20 * - On flush(), the encoded data stream is synchronized such that
21 * all data compressed up to this point can be fully decompressed.
23 * - On finish(), the encoded data stream is finalized an a Gzip
24 * end of data marker is emitted.
27 * When decompressing:
29 * - The encoder will transition to isfinished() == true on its own
30 * if a Gzip end of data marker is detected in the input. After
31 * this point, no additional data can be decompressed.
35 class WvGzipEncoder : public WvEncoder
37 public:
38 enum Mode {
39 Deflate, /*!< Compress using deflate */
40 Inflate /*!< Decompress using inflate */
43 /**
44 * Creates a Gzip encoder.
46 * "mode" is the compression mode
48 WvGzipEncoder(Mode mode, size_t _out_limit = 0);
49 virtual ~WvGzipEncoder();
51 /**
52 * Limit the amount of output produced in one call to encode().
53 * Defaults to 0, meaning no limit (empty the input buffer).
55 size_t out_limit;
57 /**
58 * Continue decompression if errors are found.
59 * If true, upon running into a decompression error, the encoder will
60 * seek to the next unbroken block. Most useful if at least some blocks
61 * are fully flushed (see 'full_flush' below). Defaults to false.
62 * Note that it may be impossible to ignore really bad decompression
63 * errors, in which case the encoder will go !isok(), as it would
64 * if this boolean is false.
66 bool ignore_decompression_errors;
68 /**
69 * Do full flushes.
70 * Makes the encoder use Z_FULL_FLUSH instead of Z_SYNC_FLUSH, which
71 * resets the compression state to improve chances of recovering
72 * corrupted compressed data. Degrades compression, so don't use it too
73 * often. Defaults to false.
75 bool full_flush;
77 protected:
78 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush);
79 virtual bool _finish(WvBuf &outbuf);
80 virtual bool _reset();
82 private:
83 struct z_stream_s *zstr;
84 WvInPlaceBuf tmpbuf;
85 Mode mode;
86 size_t output;
88 void init();
89 void close();
90 void prepare(WvBuf *inbuf);
91 bool process(WvBuf &outbuf, bool flush, bool finish);
95 #endif // __WVGZIP_H