]>
Commit | Line | Data |
---|---|---|
79c3e0e1 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ce7208d4 | 2 | // Name: wx/zstream.h |
79c3e0e1 GL |
3 | // Purpose: Memory stream classes |
4 | // Author: Guilhem Lavaux | |
0915d0b2 | 5 | // Modified by: Mike Wetherell |
79c3e0e1 GL |
6 | // Created: 11/07/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
65571936 | 9 | // Licence: wxWindows licence |
79c3e0e1 | 10 | ///////////////////////////////////////////////////////////////////////////// |
34138703 JS |
11 | #ifndef _WX_WXZSTREAM_H__ |
12 | #define _WX_WXZSTREAM_H__ | |
79c3e0e1 | 13 | |
124031d5 | 14 | #include "wx/defs.h" |
ac57418f | 15 | |
ce4169a4 | 16 | #if wxUSE_ZLIB && wxUSE_STREAMS |
ac57418f | 17 | |
ed58dbea | 18 | #include "wx/stream.h" |
79c3e0e1 | 19 | |
0915d0b2 VZ |
20 | // Compression level |
21 | enum { | |
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 { | |
4c68a102 VS |
30 | #if WXWIN_COMPATIBILITY_2_4 |
31 | wxZLIB_24COMPATIBLE = 4, // read v2.4.x data without error | |
32 | #endif | |
33 | wxZLIB_NO_HEADER = 0, // raw deflate stream, no header or checksum | |
34 | wxZLIB_ZLIB = 1, // zlib header and checksum | |
35 | wxZLIB_GZIP = 2, // gzip header and checksum, requires zlib 1.2.1+ | |
36 | wxZLIB_AUTO = 3 // autodetect header zlib or gzip | |
0915d0b2 VZ |
37 | }; |
38 | ||
bddd7a8d | 39 | class WXDLLIMPEXP_BASE wxZlibInputStream: public wxFilterInputStream { |
79c3e0e1 | 40 | public: |
4c68a102 | 41 | wxZlibInputStream(wxInputStream& stream, int flags = wxZLIB_AUTO); |
55420742 | 42 | wxZlibInputStream(wxInputStream *stream, int flags = wxZLIB_AUTO); |
79c3e0e1 GL |
43 | virtual ~wxZlibInputStream(); |
44 | ||
0915d0b2 | 45 | char Peek() { return wxInputStream::Peek(); } |
588066b7 | 46 | wxFileOffset GetLength() const { return wxInputStream::GetLength(); } |
0915d0b2 | 47 | |
4c68a102 VS |
48 | static bool CanHandleGZip(); |
49 | ||
79c3e0e1 | 50 | protected: |
75ed1d15 | 51 | size_t OnSysRead(void *buffer, size_t size); |
4004775e | 52 | wxFileOffset OnSysTell() const { return m_pos; } |
1678ad78 | 53 | |
55420742 MW |
54 | private: |
55 | void Init(int flags); | |
56 | ||
1678ad78 | 57 | protected: |
79c3e0e1 GL |
58 | size_t m_z_size; |
59 | unsigned char *m_z_buffer; | |
856d2e52 | 60 | struct z_stream_s *m_inflate; |
4004775e | 61 | wxFileOffset m_pos; |
4c68a102 VS |
62 | #if WXWIN_COMPATIBILITY_2_4 |
63 | bool m_24compatibilty; | |
64 | #endif | |
22f3361e | 65 | |
4c68a102 | 66 | DECLARE_NO_COPY_CLASS(wxZlibInputStream) |
79c3e0e1 GL |
67 | }; |
68 | ||
bddd7a8d | 69 | class WXDLLIMPEXP_BASE wxZlibOutputStream: public wxFilterOutputStream { |
79c3e0e1 | 70 | public: |
301deecc | 71 | wxZlibOutputStream(wxOutputStream& stream, int level = -1, int flags = wxZLIB_ZLIB); |
55420742 | 72 | wxZlibOutputStream(wxOutputStream *stream, int level = -1, int flags = wxZLIB_ZLIB); |
8f0ff178 | 73 | virtual ~wxZlibOutputStream() { Close(); } |
79c3e0e1 | 74 | |
0915d0b2 | 75 | void Sync() { DoFlush(false); } |
8f0ff178 | 76 | bool Close(); |
588066b7 | 77 | wxFileOffset GetLength() const { return m_pos; } |
79c3e0e1 | 78 | |
4c68a102 VS |
79 | static bool CanHandleGZip(); |
80 | ||
79c3e0e1 | 81 | protected: |
75ed1d15 | 82 | size_t OnSysWrite(const void *buffer, size_t size); |
4004775e | 83 | wxFileOffset OnSysTell() const { return m_pos; } |
0915d0b2 VZ |
84 | |
85 | virtual void DoFlush(bool final); | |
1678ad78 | 86 | |
55420742 MW |
87 | private: |
88 | void Init(int level, int flags); | |
89 | ||
1678ad78 | 90 | protected: |
79c3e0e1 GL |
91 | size_t m_z_size; |
92 | unsigned char *m_z_buffer; | |
856d2e52 | 93 | struct z_stream_s *m_deflate; |
4004775e | 94 | wxFileOffset m_pos; |
22f3361e | 95 | |
4c68a102 | 96 | DECLARE_NO_COPY_CLASS(wxZlibOutputStream) |
79c3e0e1 GL |
97 | }; |
98 | ||
55420742 MW |
99 | class WXDLLIMPEXP_BASE wxZlibClassFactory: public wxFilterClassFactory |
100 | { | |
101 | public: | |
102 | wxZlibClassFactory(); | |
103 | ||
104 | wxFilterInputStream *NewStream(wxInputStream& stream) const | |
105 | { return new wxZlibInputStream(stream); } | |
106 | wxFilterOutputStream *NewStream(wxOutputStream& stream) const | |
107 | { return new wxZlibOutputStream(stream, -1); } | |
108 | wxFilterInputStream *NewStream(wxInputStream *stream) const | |
109 | { return new wxZlibInputStream(stream); } | |
110 | wxFilterOutputStream *NewStream(wxOutputStream *stream) const | |
111 | { return new wxZlibOutputStream(stream, -1); } | |
112 | ||
113 | const wxChar * const *GetProtocols(wxStreamProtocolType type | |
114 | = wxSTREAM_PROTOCOL) const; | |
115 | ||
116 | private: | |
117 | DECLARE_DYNAMIC_CLASS(wxZlibClassFactory) | |
118 | }; | |
119 | ||
120 | class WXDLLIMPEXP_BASE wxGzipClassFactory: public wxFilterClassFactory | |
121 | { | |
122 | public: | |
123 | wxGzipClassFactory(); | |
124 | ||
125 | wxFilterInputStream *NewStream(wxInputStream& stream) const | |
126 | { return new wxZlibInputStream(stream); } | |
127 | wxFilterOutputStream *NewStream(wxOutputStream& stream) const | |
128 | { return new wxZlibOutputStream(stream, -1); } | |
129 | wxFilterInputStream *NewStream(wxInputStream *stream) const | |
130 | { return new wxZlibInputStream(stream); } | |
131 | wxFilterOutputStream *NewStream(wxOutputStream *stream) const | |
132 | { return new wxZlibOutputStream(stream, -1); } | |
133 | ||
134 | const wxChar * const *GetProtocols(wxStreamProtocolType type | |
135 | = wxSTREAM_PROTOCOL) const; | |
136 | ||
137 | private: | |
138 | DECLARE_DYNAMIC_CLASS(wxGzipClassFactory) | |
139 | }; | |
140 | ||
79c3e0e1 | 141 | #endif |
ce4169a4 | 142 | // wxUSE_ZLIB && wxUSE_STREAMS |
ac57418f RR |
143 | |
144 | #endif | |
cc985fac PA |
145 | // _WX_WXZSTREAM_H__ |
146 |