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"
22 wxZ_DEFAULT_COMPRESSION
= -1,
23 wxZ_NO_COMPRESSION
= 0,
25 wxZ_BEST_COMPRESSION
= 9
30 #if WXWIN_COMPATIBILITY_2_4
31 wxZLIB_24COMPATIBLE
= 4, // read v2.4.x data without error
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
39 class WXDLLIMPEXP_BASE wxZlibInputStream
: public wxFilterInputStream
{
41 wxZlibInputStream(wxInputStream
& stream
, int flags
= wxZLIB_AUTO
);
42 wxZlibInputStream(wxInputStream
*stream
, int flags
= wxZLIB_AUTO
);
43 virtual ~wxZlibInputStream();
45 char Peek() { return wxInputStream::Peek(); }
46 wxFileOffset
GetLength() const { return wxInputStream::GetLength(); }
48 static bool CanHandleGZip();
51 size_t OnSysRead(void *buffer
, size_t size
);
52 wxFileOffset
OnSysTell() const { return m_pos
; }
59 unsigned char *m_z_buffer
;
60 struct z_stream_s
*m_inflate
;
62 #if WXWIN_COMPATIBILITY_2_4
63 bool m_24compatibilty
;
66 DECLARE_NO_COPY_CLASS(wxZlibInputStream
)
69 class WXDLLIMPEXP_BASE wxZlibOutputStream
: public wxFilterOutputStream
{
71 wxZlibOutputStream(wxOutputStream
& stream
, int level
= -1, int flags
= wxZLIB_ZLIB
);
72 wxZlibOutputStream(wxOutputStream
*stream
, int level
= -1, int flags
= wxZLIB_ZLIB
);
73 virtual ~wxZlibOutputStream() { Close(); }
75 void Sync() { DoFlush(false); }
77 wxFileOffset
GetLength() const { return m_pos
; }
79 static bool CanHandleGZip();
82 size_t OnSysWrite(const void *buffer
, size_t size
);
83 wxFileOffset
OnSysTell() const { return m_pos
; }
85 virtual void DoFlush(bool final
);
88 void Init(int level
, int flags
);
92 unsigned char *m_z_buffer
;
93 struct z_stream_s
*m_deflate
;
96 DECLARE_NO_COPY_CLASS(wxZlibOutputStream
)
99 class WXDLLIMPEXP_BASE wxZlibClassFactory
: public wxFilterClassFactory
102 wxZlibClassFactory();
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); }
113 const wxChar
* const *GetProtocols(wxStreamProtocolType type
114 = wxSTREAM_PROTOCOL
) const;
117 DECLARE_DYNAMIC_CLASS(wxZlibClassFactory
)
120 class WXDLLIMPEXP_BASE wxGzipClassFactory
: public wxFilterClassFactory
123 wxGzipClassFactory();
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); }
134 const wxChar
* const *GetProtocols(wxStreamProtocolType type
135 = wxSTREAM_PROTOCOL
) const;
138 DECLARE_DYNAMIC_CLASS(wxGzipClassFactory
)
142 // wxUSE_ZLIB && wxUSE_STREAMS