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 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
36 class WXDLLIMPEXP_BASE wxZlibInputStream
: public wxFilterInputStream
{
38 wxZlibInputStream(wxInputStream
& stream
, int flags
= wxZLIB_AUTO
);
39 wxZlibInputStream(wxInputStream
*stream
, int flags
= wxZLIB_AUTO
);
40 virtual ~wxZlibInputStream();
42 char Peek() { return wxInputStream::Peek(); }
43 wxFileOffset
GetLength() const { return wxInputStream::GetLength(); }
45 static bool CanHandleGZip();
48 size_t OnSysRead(void *buffer
, size_t size
);
49 wxFileOffset
OnSysTell() const { return m_pos
; }
56 unsigned char *m_z_buffer
;
57 struct z_stream_s
*m_inflate
;
60 DECLARE_NO_COPY_CLASS(wxZlibInputStream
)
63 class WXDLLIMPEXP_BASE wxZlibOutputStream
: public wxFilterOutputStream
{
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(); }
69 void Sync() { DoFlush(false); }
71 wxFileOffset
GetLength() const { return m_pos
; }
73 static bool CanHandleGZip();
76 size_t OnSysWrite(const void *buffer
, size_t size
);
77 wxFileOffset
OnSysTell() const { return m_pos
; }
79 virtual void DoFlush(bool final
);
82 void Init(int level
, int flags
);
86 unsigned char *m_z_buffer
;
87 struct z_stream_s
*m_deflate
;
90 DECLARE_NO_COPY_CLASS(wxZlibOutputStream
)
93 class WXDLLIMPEXP_BASE wxZlibClassFactory
: public wxFilterClassFactory
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); }
107 const wxChar
* const *GetProtocols(wxStreamProtocolType type
108 = wxSTREAM_PROTOCOL
) const;
111 DECLARE_DYNAMIC_CLASS(wxZlibClassFactory
)
114 class WXDLLIMPEXP_BASE wxGzipClassFactory
: public wxFilterClassFactory
117 wxGzipClassFactory();
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); }
128 const wxChar
* const *GetProtocols(wxStreamProtocolType type
129 = wxSTREAM_PROTOCOL
) const;
132 DECLARE_DYNAMIC_CLASS(wxGzipClassFactory
)
136 // wxUSE_ZLIB && wxUSE_STREAMS