1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Memory stream classes
4 // Author: Guilhem Lavaux
5 // Modified by: Mike Wetherell
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_WXZSTREAM_H__
12 #define _WX_WXZSTREAM_H__
16 #if wxUSE_ZLIB && wxUSE_STREAMS
18 #include "wx/stream.h"
19 #include "wx/versioninfo.h"
22 enum wxZlibCompressionLevels
{
23 wxZ_DEFAULT_COMPRESSION
= -1,
24 wxZ_NO_COMPRESSION
= 0,
26 wxZ_BEST_COMPRESSION
= 9
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
37 class WXDLLIMPEXP_BASE wxZlibInputStream
: public wxFilterInputStream
{
39 wxZlibInputStream(wxInputStream
& stream
, int flags
= wxZLIB_AUTO
);
40 wxZlibInputStream(wxInputStream
*stream
, int flags
= wxZLIB_AUTO
);
41 virtual ~wxZlibInputStream();
43 char Peek() { return wxInputStream::Peek(); }
44 wxFileOffset
GetLength() const { return wxInputStream::GetLength(); }
46 static bool CanHandleGZip();
48 bool SetDictionary(const char *data
, const size_t datalen
);
49 bool SetDictionary(const wxMemoryBuffer
&buf
);
52 size_t OnSysRead(void *buffer
, size_t size
);
53 wxFileOffset
OnSysTell() const { return m_pos
; }
60 unsigned char *m_z_buffer
;
61 struct z_stream_s
*m_inflate
;
64 wxDECLARE_NO_COPY_CLASS(wxZlibInputStream
);
67 class WXDLLIMPEXP_BASE wxZlibOutputStream
: public wxFilterOutputStream
{
69 wxZlibOutputStream(wxOutputStream
& stream
, int level
= -1, int flags
= wxZLIB_ZLIB
);
70 wxZlibOutputStream(wxOutputStream
*stream
, int level
= -1, int flags
= wxZLIB_ZLIB
);
71 virtual ~wxZlibOutputStream() { Close(); }
73 void Sync() { DoFlush(false); }
75 wxFileOffset
GetLength() const { return m_pos
; }
77 static bool CanHandleGZip();
79 bool SetDictionary(const char *data
, const size_t datalen
);
80 bool SetDictionary(const wxMemoryBuffer
&buf
);
83 size_t OnSysWrite(const void *buffer
, size_t size
);
84 wxFileOffset
OnSysTell() const { return m_pos
; }
86 virtual void DoFlush(bool final
);
89 void Init(int level
, int flags
);
93 unsigned char *m_z_buffer
;
94 struct z_stream_s
*m_deflate
;
97 wxDECLARE_NO_COPY_CLASS(wxZlibOutputStream
);
100 class WXDLLIMPEXP_BASE wxZlibClassFactory
: public wxFilterClassFactory
103 wxZlibClassFactory();
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); }
114 const wxChar
* const *GetProtocols(wxStreamProtocolType type
115 = wxSTREAM_PROTOCOL
) const;
118 DECLARE_DYNAMIC_CLASS(wxZlibClassFactory
)
121 class WXDLLIMPEXP_BASE wxGzipClassFactory
: public wxFilterClassFactory
124 wxGzipClassFactory();
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); }
135 const wxChar
* const *GetProtocols(wxStreamProtocolType type
136 = wxSTREAM_PROTOCOL
) const;
139 DECLARE_DYNAMIC_CLASS(wxGzipClassFactory
)
142 WXDLLIMPEXP_BASE wxVersionInfo
wxGetZlibVersionInfo();
145 // wxUSE_ZLIB && wxUSE_STREAMS