1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        zstream.h
3 // Purpose:     interface of wxZlibOutputStream
4 // Author:      wxWidgets team
5 // Licence:     wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
7 
8 
9 /// Compression level
10 enum wxZlibCompressionLevels {
11     wxZ_DEFAULT_COMPRESSION = -1,
12     wxZ_NO_COMPRESSION = 0,
13     wxZ_BEST_SPEED = 1,
14     wxZ_BEST_COMPRESSION = 9
15 };
16 
17 /// Flags
18 enum wxZLibFlags {
19     wxZLIB_NO_HEADER = 0,    //!< raw deflate stream, no header or checksum
20     wxZLIB_ZLIB = 1,         //!< zlib header and checksum
21     wxZLIB_GZIP = 2,         //!< gzip header and checksum, requires zlib 1.2.1+
22     wxZLIB_AUTO = 3          //!< autodetect header zlib or gzip
23 };
24 
25 
26 /**
27     @class wxZlibOutputStream
28 
29     This stream compresses all data written to it.
30 
31     The compressed output can be in zlib or gzip format.
32     Note that writing the gzip format requires zlib version 1.2.1 or greater
33     (the builtin version does support gzip format).
34 
35     The stream is not seekable, wxOutputStream::SeekO() returns
36     ::wxInvalidOffset.
37 
38     @library{wxbase}
39     @category{archive,streams}
40 
41     @see wxOutputStream, wxZlibInputStream
42 */
43 class wxZlibOutputStream : public wxFilterOutputStream
44 {
45 public:
46     //@{
47     /**
48         Creates a new write-only compressed stream.
49 
50         @a level means level of compression. It is number between 0 and 9
51         (including these values) where 0 means no compression and 9 best but
52         slowest compression. -1 is default value (currently equivalent to 6).
53 
54         If the parent stream is passed as a pointer then the new filter stream
55         takes ownership of it. If it is passed by reference then it does not.
56 
57         The @a flags wxZLIB_ZLIB and wxZLIB_GZIP specify whether the output data
58         will be in zlib or gzip format. wxZLIB_ZLIB is the default.
59 
60         If @a flags is wxZLIB_NO_HEADER, then a raw deflate stream is output
61         without either zlib or gzip headers. This is a lower level mode, which
62         is not usually used directly. It can be used to embed a raw deflate
63         stream in a higher level protocol.
64 
65         The values of the ::wxZlibCompressionLevels and ::wxZLibFlags
66         enumerations can be used.
67     */
68     wxZlibOutputStream(wxOutputStream& stream, int level = -1,
69                        int flags = wxZLIB_ZLIB);
70     wxZlibOutputStream(wxOutputStream* stream, int level = -1,
71                        int flags = wxZLIB_ZLIB);
72     //@}
73 
74     /**
75         Returns @true if zlib library in use can handle gzip compressed data.
76     */
77     static bool CanHandleGZip();
78 
79     //@{
80     /**
81         Sets the dictionary to the specified chunk of data. This can improve
82         compression rate but note that the dictionary has to be the same when
83         you deflate the data as when you inflate the data, otherwise you
84         will inflate corrupted data.
85 
86         Returns @true if the dictionary was successfully set.
87     */
88     bool SetDictionary(const char *data, size_t datalen);
89     bool SetDictionary(const wxMemoryBuffer &buf);
90     //@}
91 };
92 
93 
94 
95 /**
96     @class wxZlibInputStream
97 
98     This filter stream decompresses a stream that is in zlib or gzip format.
99     Note that reading the gzip format requires zlib version 1.2.1 or greater,
100     (the builtin version does support gzip format).
101 
102     The stream is not seekable, wxInputStream::SeekI returns ::wxInvalidOffset.
103     Also wxStreamBase::GetSize() is not supported, it always returns 0.
104 
105     @library{wxbase}
106     @category{archive,streams}
107 
108     @see wxInputStream, wxZlibOutputStream.
109 */
110 class wxZlibInputStream : public wxFilterInputStream
111 {
112 public:
113     //@{
114     /**
115         If the parent stream is passed as a pointer then the new filter stream
116         takes ownership of it. If it is passed by reference then it does not.
117 
118         The @a flags wxZLIB_ZLIB and wxZLIB_GZIP specify whether the input data
119         is in zlib or gzip format. If wxZLIB_AUTO is used, then zlib will
120         autodetect the stream type, this is the default.
121 
122         If @a flags is wxZLIB_NO_HEADER, then the data is assumed to be a raw
123         deflate stream without either zlib or gzip headers. This is a lower level
124         mode, which is not usually used directly. It can be used to read a raw
125         deflate stream embedded in a higher level protocol.
126 
127         The values of the ::wxZLibFlags enumeration can be used.
128     */
129     wxZlibInputStream(wxInputStream& stream, int flags = wxZLIB_AUTO);
130     wxZlibInputStream(wxInputStream* stream, int flags = wxZLIB_AUTO);
131     //@}
132 
133     /**
134         Returns @true if zlib library in use can handle gzip compressed data.
135     */
136     static bool CanHandleGZip();
137 
138     //@{
139     /**
140         Sets the dictionary to the specified chunk of data. This can improve
141         compression rate but note that the dictionary has to be the same when
142         you deflate the data as when you inflate the data, otherwise you
143         will inflate corrupted data.
144 
145         Returns @true if the dictionary was successfully set.
146     */
147     bool SetDictionary(const char *data, size_t datalen);
148     bool SetDictionary(const wxMemoryBuffer &buf);
149     //@}
150 };
151 
152