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