]> git.saurik.com Git - wxWidgets.git/blame - include/wx/zstream.h
synchronize GTK2 minimum version in docs
[wxWidgets.git] / include / wx / zstream.h
CommitLineData
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"
ccec9093 19#include "wx/versioninfo.h"
79c3e0e1 20
0915d0b2 21// Compression level
75bc3a0d 22enum wxZlibCompressionLevels {
0915d0b2
VZ
23 wxZ_DEFAULT_COMPRESSION = -1,
24 wxZ_NO_COMPRESSION = 0,
25 wxZ_BEST_SPEED = 1,
26 wxZ_BEST_COMPRESSION = 9
27};
28
29// Flags
75bc3a0d 30enum wxZLibFlags {
4c68a102
VS
31 wxZLIB_NO_HEADER = 0, // raw deflate stream, no header or checksum
32 wxZLIB_ZLIB = 1, // zlib header and checksum
33 wxZLIB_GZIP = 2, // gzip header and checksum, requires zlib 1.2.1+
34 wxZLIB_AUTO = 3 // autodetect header zlib or gzip
0915d0b2
VZ
35};
36
bddd7a8d 37class WXDLLIMPEXP_BASE wxZlibInputStream: public wxFilterInputStream {
79c3e0e1 38 public:
4c68a102 39 wxZlibInputStream(wxInputStream& stream, int flags = wxZLIB_AUTO);
55420742 40 wxZlibInputStream(wxInputStream *stream, int flags = wxZLIB_AUTO);
79c3e0e1
GL
41 virtual ~wxZlibInputStream();
42
0915d0b2 43 char Peek() { return wxInputStream::Peek(); }
588066b7 44 wxFileOffset GetLength() const { return wxInputStream::GetLength(); }
0915d0b2 45
4c68a102
VS
46 static bool CanHandleGZip();
47
51acf83b
VZ
48 bool SetDictionary(const char *data, const size_t datalen);
49 bool SetDictionary(const wxMemoryBuffer &buf);
50
79c3e0e1 51 protected:
75ed1d15 52 size_t OnSysRead(void *buffer, size_t size);
4004775e 53 wxFileOffset OnSysTell() const { return m_pos; }
1678ad78 54
55420742
MW
55 private:
56 void Init(int flags);
57
1678ad78 58 protected:
79c3e0e1
GL
59 size_t m_z_size;
60 unsigned char *m_z_buffer;
856d2e52 61 struct z_stream_s *m_inflate;
4004775e 62 wxFileOffset m_pos;
22f3361e 63
c0c133e1 64 wxDECLARE_NO_COPY_CLASS(wxZlibInputStream);
79c3e0e1
GL
65};
66
bddd7a8d 67class WXDLLIMPEXP_BASE wxZlibOutputStream: public wxFilterOutputStream {
79c3e0e1 68 public:
301deecc 69 wxZlibOutputStream(wxOutputStream& stream, int level = -1, int flags = wxZLIB_ZLIB);
55420742 70 wxZlibOutputStream(wxOutputStream *stream, int level = -1, int flags = wxZLIB_ZLIB);
8f0ff178 71 virtual ~wxZlibOutputStream() { Close(); }
79c3e0e1 72
0915d0b2 73 void Sync() { DoFlush(false); }
8f0ff178 74 bool Close();
588066b7 75 wxFileOffset GetLength() const { return m_pos; }
79c3e0e1 76
4c68a102
VS
77 static bool CanHandleGZip();
78
51acf83b
VZ
79 bool SetDictionary(const char *data, const size_t datalen);
80 bool SetDictionary(const wxMemoryBuffer &buf);
81
79c3e0e1 82 protected:
75ed1d15 83 size_t OnSysWrite(const void *buffer, size_t size);
4004775e 84 wxFileOffset OnSysTell() const { return m_pos; }
0915d0b2
VZ
85
86 virtual void DoFlush(bool final);
1678ad78 87
55420742
MW
88 private:
89 void Init(int level, int flags);
90
1678ad78 91 protected:
79c3e0e1
GL
92 size_t m_z_size;
93 unsigned char *m_z_buffer;
856d2e52 94 struct z_stream_s *m_deflate;
4004775e 95 wxFileOffset m_pos;
22f3361e 96
c0c133e1 97 wxDECLARE_NO_COPY_CLASS(wxZlibOutputStream);
79c3e0e1
GL
98};
99
55420742
MW
100class WXDLLIMPEXP_BASE wxZlibClassFactory: public wxFilterClassFactory
101{
102public:
103 wxZlibClassFactory();
104
105 wxFilterInputStream *NewStream(wxInputStream& stream) const
106 { return new wxZlibInputStream(stream); }
107 wxFilterOutputStream *NewStream(wxOutputStream& stream) const
108 { return new wxZlibOutputStream(stream, -1); }
109 wxFilterInputStream *NewStream(wxInputStream *stream) const
110 { return new wxZlibInputStream(stream); }
111 wxFilterOutputStream *NewStream(wxOutputStream *stream) const
112 { return new wxZlibOutputStream(stream, -1); }
113
114 const wxChar * const *GetProtocols(wxStreamProtocolType type
115 = wxSTREAM_PROTOCOL) const;
116
117private:
118 DECLARE_DYNAMIC_CLASS(wxZlibClassFactory)
119};
120
121class WXDLLIMPEXP_BASE wxGzipClassFactory: public wxFilterClassFactory
122{
123public:
124 wxGzipClassFactory();
125
126 wxFilterInputStream *NewStream(wxInputStream& stream) const
127 { return new wxZlibInputStream(stream); }
128 wxFilterOutputStream *NewStream(wxOutputStream& stream) const
129 { return new wxZlibOutputStream(stream, -1); }
130 wxFilterInputStream *NewStream(wxInputStream *stream) const
131 { return new wxZlibInputStream(stream); }
132 wxFilterOutputStream *NewStream(wxOutputStream *stream) const
133 { return new wxZlibOutputStream(stream, -1); }
134
135 const wxChar * const *GetProtocols(wxStreamProtocolType type
136 = wxSTREAM_PROTOCOL) const;
137
138private:
139 DECLARE_DYNAMIC_CLASS(wxGzipClassFactory)
140};
141
ccec9093
VZ
142WXDLLIMPEXP_BASE wxVersionInfo wxGetZlibVersionInfo();
143
79c3e0e1 144#endif
ce4169a4 145 // wxUSE_ZLIB && wxUSE_STREAMS
ac57418f
RR
146
147#endif
cc985fac
PA
148 // _WX_WXZSTREAM_H__
149