/src/wxwidgets/include/wx/zstream.h
Line | Count | Source (jump to first uncovered line) |
1 | | ///////////////////////////////////////////////////////////////////////////// |
2 | | // Name: wx/zstream.h |
3 | | // Purpose: Memory stream classes |
4 | | // Author: Guilhem Lavaux |
5 | | // Modified by: Mike Wetherell |
6 | | // Created: 11/07/98 |
7 | | // Copyright: (c) Guilhem Lavaux |
8 | | // Licence: wxWindows licence |
9 | | ///////////////////////////////////////////////////////////////////////////// |
10 | | #ifndef _WX_WXZSTREAM_H__ |
11 | | #define _WX_WXZSTREAM_H__ |
12 | | |
13 | | #include "wx/defs.h" |
14 | | |
15 | | #if wxUSE_ZLIB && wxUSE_STREAMS |
16 | | |
17 | | #include "wx/stream.h" |
18 | | #include "wx/versioninfo.h" |
19 | | |
20 | | // Compression level |
21 | | enum wxZlibCompressionLevels { |
22 | | wxZ_DEFAULT_COMPRESSION = -1, |
23 | | wxZ_NO_COMPRESSION = 0, |
24 | | wxZ_BEST_SPEED = 1, |
25 | | wxZ_BEST_COMPRESSION = 9 |
26 | | }; |
27 | | |
28 | | // Flags |
29 | | enum wxZLibFlags { |
30 | | wxZLIB_NO_HEADER = 0, // raw deflate stream, no header or checksum |
31 | | wxZLIB_ZLIB = 1, // zlib header and checksum |
32 | | wxZLIB_GZIP = 2, // gzip header and checksum, requires zlib 1.2.1+ |
33 | | wxZLIB_AUTO = 3 // autodetect header zlib or gzip |
34 | | }; |
35 | | |
36 | | class WXDLLIMPEXP_BASE wxZlibInputStream: public wxFilterInputStream { |
37 | | public: |
38 | | wxZlibInputStream(wxInputStream& stream, int flags = wxZLIB_AUTO); |
39 | | wxZlibInputStream(wxInputStream *stream, int flags = wxZLIB_AUTO); |
40 | | virtual ~wxZlibInputStream(); |
41 | | |
42 | 0 | char Peek() override { return wxInputStream::Peek(); } |
43 | 0 | wxFileOffset GetLength() const override { return wxInputStream::GetLength(); } |
44 | | |
45 | | static bool CanHandleGZip(); |
46 | | |
47 | | bool SetDictionary(const char *data, size_t datalen); |
48 | | bool SetDictionary(const wxMemoryBuffer &buf); |
49 | | |
50 | | protected: |
51 | | size_t OnSysRead(void *buffer, size_t size) override; |
52 | 0 | wxFileOffset OnSysTell() const override { return m_pos; } |
53 | | |
54 | | private: |
55 | | void Init(int flags); |
56 | | |
57 | | protected: |
58 | | size_t m_z_size; |
59 | | unsigned char *m_z_buffer; |
60 | | struct z_stream_s *m_inflate; |
61 | | wxFileOffset m_pos; |
62 | | |
63 | | wxDECLARE_NO_COPY_CLASS(wxZlibInputStream); |
64 | | }; |
65 | | |
66 | | class WXDLLIMPEXP_BASE wxZlibOutputStream: public wxFilterOutputStream { |
67 | | public: |
68 | | wxZlibOutputStream(wxOutputStream& stream, int level = -1, int flags = wxZLIB_ZLIB); |
69 | | wxZlibOutputStream(wxOutputStream *stream, int level = -1, int flags = wxZLIB_ZLIB); |
70 | 0 | virtual ~wxZlibOutputStream() { Close(); } |
71 | | |
72 | 0 | void Sync() override { DoFlush(false); } |
73 | | bool Close() override; |
74 | 0 | wxFileOffset GetLength() const override { return m_pos; } |
75 | | |
76 | | static bool CanHandleGZip(); |
77 | | |
78 | | bool SetDictionary(const char *data, size_t datalen); |
79 | | bool SetDictionary(const wxMemoryBuffer &buf); |
80 | | |
81 | | protected: |
82 | | size_t OnSysWrite(const void *buffer, size_t size) override; |
83 | 0 | wxFileOffset OnSysTell() const override { return m_pos; } |
84 | | |
85 | | virtual void DoFlush(bool final); |
86 | | |
87 | | private: |
88 | | void Init(int level, int flags); |
89 | | |
90 | | protected: |
91 | | size_t m_z_size; |
92 | | unsigned char *m_z_buffer; |
93 | | struct z_stream_s *m_deflate; |
94 | | wxFileOffset m_pos; |
95 | | |
96 | | wxDECLARE_NO_COPY_CLASS(wxZlibOutputStream); |
97 | | }; |
98 | | |
99 | | class WXDLLIMPEXP_BASE wxZlibClassFactory: public wxFilterClassFactory |
100 | | { |
101 | | public: |
102 | | wxZlibClassFactory(); |
103 | | |
104 | | wxFilterInputStream *NewStream(wxInputStream& stream) const override |
105 | 0 | { return new wxZlibInputStream(stream); } |
106 | | wxFilterOutputStream *NewStream(wxOutputStream& stream) const override |
107 | 0 | { return new wxZlibOutputStream(stream, -1); } |
108 | | wxFilterInputStream *NewStream(wxInputStream *stream) const override |
109 | 0 | { return new wxZlibInputStream(stream); } |
110 | | wxFilterOutputStream *NewStream(wxOutputStream *stream) const override |
111 | 0 | { return new wxZlibOutputStream(stream, -1); } |
112 | | |
113 | | const wxChar * const *GetProtocols(wxStreamProtocolType type |
114 | | = wxSTREAM_PROTOCOL) const override; |
115 | | |
116 | | private: |
117 | | wxDECLARE_DYNAMIC_CLASS(wxZlibClassFactory); |
118 | | }; |
119 | | |
120 | | class WXDLLIMPEXP_BASE wxGzipClassFactory: public wxFilterClassFactory |
121 | | { |
122 | | public: |
123 | | wxGzipClassFactory(); |
124 | | |
125 | | wxFilterInputStream *NewStream(wxInputStream& stream) const override |
126 | 0 | { return new wxZlibInputStream(stream); } |
127 | | wxFilterOutputStream *NewStream(wxOutputStream& stream) const override |
128 | 0 | { return new wxZlibOutputStream(stream, -1); } |
129 | | wxFilterInputStream *NewStream(wxInputStream *stream) const override |
130 | 0 | { return new wxZlibInputStream(stream); } |
131 | | wxFilterOutputStream *NewStream(wxOutputStream *stream) const override |
132 | 0 | { return new wxZlibOutputStream(stream, -1); } |
133 | | |
134 | | const wxChar * const *GetProtocols(wxStreamProtocolType type |
135 | | = wxSTREAM_PROTOCOL) const override; |
136 | | |
137 | | private: |
138 | | wxDECLARE_DYNAMIC_CLASS(wxGzipClassFactory); |
139 | | }; |
140 | | |
141 | | WXDLLIMPEXP_BASE wxVersionInfo wxGetZlibVersionInfo(); |
142 | | |
143 | | #endif |
144 | | // wxUSE_ZLIB && wxUSE_STREAMS |
145 | | |
146 | | #endif |
147 | | // _WX_WXZSTREAM_H__ |
148 | | |