]> git.saurik.com Git - wxWidgets.git/blob - include/wx/zstream.h
making proper resource-fork apps
[wxWidgets.git] / include / wx / zstream.h
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 // RCS-ID: $Id$
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_WXZSTREAM_H__
12 #define _WX_WXZSTREAM_H__
13
14 #include "wx/defs.h"
15
16 #if wxUSE_ZLIB && wxUSE_STREAMS
17
18 #include "wx/stream.h"
19
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 {
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 char Peek() { return wxInputStream::Peek(); }
43 wxFileOffset GetLength() const { return wxInputStream::GetLength(); }
44
45 static bool CanHandleGZip();
46
47 protected:
48 size_t OnSysRead(void *buffer, size_t size);
49 wxFileOffset OnSysTell() const { return m_pos; }
50
51 private:
52 void Init(int flags);
53
54 protected:
55 size_t m_z_size;
56 unsigned char *m_z_buffer;
57 struct z_stream_s *m_inflate;
58 wxFileOffset m_pos;
59
60 DECLARE_NO_COPY_CLASS(wxZlibInputStream)
61 };
62
63 class WXDLLIMPEXP_BASE wxZlibOutputStream: public wxFilterOutputStream {
64 public:
65 wxZlibOutputStream(wxOutputStream& stream, int level = -1, int flags = wxZLIB_ZLIB);
66 wxZlibOutputStream(wxOutputStream *stream, int level = -1, int flags = wxZLIB_ZLIB);
67 virtual ~wxZlibOutputStream() { Close(); }
68
69 void Sync() { DoFlush(false); }
70 bool Close();
71 wxFileOffset GetLength() const { return m_pos; }
72
73 static bool CanHandleGZip();
74
75 protected:
76 size_t OnSysWrite(const void *buffer, size_t size);
77 wxFileOffset OnSysTell() const { return m_pos; }
78
79 virtual void DoFlush(bool final);
80
81 private:
82 void Init(int level, int flags);
83
84 protected:
85 size_t m_z_size;
86 unsigned char *m_z_buffer;
87 struct z_stream_s *m_deflate;
88 wxFileOffset m_pos;
89
90 DECLARE_NO_COPY_CLASS(wxZlibOutputStream)
91 };
92
93 class WXDLLIMPEXP_BASE wxZlibClassFactory: public wxFilterClassFactory
94 {
95 public:
96 wxZlibClassFactory();
97
98 wxFilterInputStream *NewStream(wxInputStream& stream) const
99 { return new wxZlibInputStream(stream); }
100 wxFilterOutputStream *NewStream(wxOutputStream& stream) const
101 { return new wxZlibOutputStream(stream, -1); }
102 wxFilterInputStream *NewStream(wxInputStream *stream) const
103 { return new wxZlibInputStream(stream); }
104 wxFilterOutputStream *NewStream(wxOutputStream *stream) const
105 { return new wxZlibOutputStream(stream, -1); }
106
107 const wxChar * const *GetProtocols(wxStreamProtocolType type
108 = wxSTREAM_PROTOCOL) const;
109
110 private:
111 DECLARE_DYNAMIC_CLASS(wxZlibClassFactory)
112 };
113
114 class WXDLLIMPEXP_BASE wxGzipClassFactory: public wxFilterClassFactory
115 {
116 public:
117 wxGzipClassFactory();
118
119 wxFilterInputStream *NewStream(wxInputStream& stream) const
120 { return new wxZlibInputStream(stream); }
121 wxFilterOutputStream *NewStream(wxOutputStream& stream) const
122 { return new wxZlibOutputStream(stream, -1); }
123 wxFilterInputStream *NewStream(wxInputStream *stream) const
124 { return new wxZlibInputStream(stream); }
125 wxFilterOutputStream *NewStream(wxOutputStream *stream) const
126 { return new wxZlibOutputStream(stream, -1); }
127
128 const wxChar * const *GetProtocols(wxStreamProtocolType type
129 = wxSTREAM_PROTOCOL) const;
130
131 private:
132 DECLARE_DYNAMIC_CLASS(wxGzipClassFactory)
133 };
134
135 #endif
136 // wxUSE_ZLIB && wxUSE_STREAMS
137
138 #endif
139 // _WX_WXZSTREAM_H__
140