1998-07-14 12:06:50 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-30 11:56:12 +00:00
|
|
|
// Name: wx/zstream.h
|
1998-07-14 12:06:50 +00:00
|
|
|
// Purpose: Memory stream classes
|
|
|
|
// Author: Guilhem Lavaux
|
2003-09-26 20:07:22 +00:00
|
|
|
// Modified by: Mike Wetherell
|
1998-07-14 12:06:50 +00:00
|
|
|
// Created: 11/07/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Guilhem Lavaux
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-07-14 12:06:50 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_WXZSTREAM_H__
|
|
|
|
#define _WX_WXZSTREAM_H__
|
1998-07-14 12:06:50 +00:00
|
|
|
|
1999-01-04 18:34:42 +00:00
|
|
|
#include "wx/defs.h"
|
1999-01-04 13:52:06 +00:00
|
|
|
|
1999-06-15 20:21:59 +00:00
|
|
|
#if wxUSE_ZLIB && wxUSE_STREAMS
|
1999-01-04 13:52:06 +00:00
|
|
|
|
1999-08-20 22:52:21 +00:00
|
|
|
#include "wx/stream.h"
|
1998-07-14 12:06:50 +00:00
|
|
|
|
2003-09-26 20:07:22 +00:00
|
|
|
// Compression level
|
2008-09-27 10:58:15 +00:00
|
|
|
enum wxZlibCompressionLevels {
|
2003-09-26 20:07:22 +00:00
|
|
|
wxZ_DEFAULT_COMPRESSION = -1,
|
|
|
|
wxZ_NO_COMPRESSION = 0,
|
|
|
|
wxZ_BEST_SPEED = 1,
|
|
|
|
wxZ_BEST_COMPRESSION = 9
|
|
|
|
};
|
|
|
|
|
|
|
|
// Flags
|
2008-09-27 10:58:15 +00:00
|
|
|
enum wxZLibFlags {
|
2004-04-11 19:34:56 +00:00
|
|
|
wxZLIB_NO_HEADER = 0, // raw deflate stream, no header or checksum
|
|
|
|
wxZLIB_ZLIB = 1, // zlib header and checksum
|
|
|
|
wxZLIB_GZIP = 2, // gzip header and checksum, requires zlib 1.2.1+
|
|
|
|
wxZLIB_AUTO = 3 // autodetect header zlib or gzip
|
2003-09-26 20:07:22 +00:00
|
|
|
};
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxZlibInputStream: public wxFilterInputStream {
|
1998-07-14 12:06:50 +00:00
|
|
|
public:
|
2004-04-11 19:34:56 +00:00
|
|
|
wxZlibInputStream(wxInputStream& stream, int flags = wxZLIB_AUTO);
|
2006-10-25 20:45:15 +00:00
|
|
|
wxZlibInputStream(wxInputStream *stream, int flags = wxZLIB_AUTO);
|
1998-07-14 12:06:50 +00:00
|
|
|
virtual ~wxZlibInputStream();
|
|
|
|
|
2003-09-26 20:07:22 +00:00
|
|
|
char Peek() { return wxInputStream::Peek(); }
|
2004-11-10 21:10:30 +00:00
|
|
|
wxFileOffset GetLength() const { return wxInputStream::GetLength(); }
|
2003-09-26 20:07:22 +00:00
|
|
|
|
2004-04-11 19:34:56 +00:00
|
|
|
static bool CanHandleGZip();
|
|
|
|
|
2009-03-06 16:26:15 +00:00
|
|
|
bool SetDictionary(const char *data, const size_t datalen);
|
|
|
|
bool SetDictionary(const wxMemoryBuffer &buf);
|
|
|
|
|
1998-07-14 12:06:50 +00:00
|
|
|
protected:
|
1998-10-14 17:36:50 +00:00
|
|
|
size_t OnSysRead(void *buffer, size_t size);
|
2004-09-26 13:18:46 +00:00
|
|
|
wxFileOffset OnSysTell() const { return m_pos; }
|
1998-07-24 17:13:47 +00:00
|
|
|
|
2006-10-25 20:45:15 +00:00
|
|
|
private:
|
|
|
|
void Init(int flags);
|
|
|
|
|
1998-07-24 17:13:47 +00:00
|
|
|
protected:
|
1998-07-14 12:06:50 +00:00
|
|
|
size_t m_z_size;
|
|
|
|
unsigned char *m_z_buffer;
|
1998-09-17 17:30:13 +00:00
|
|
|
struct z_stream_s *m_inflate;
|
2004-09-26 13:18:46 +00:00
|
|
|
wxFileOffset m_pos;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxZlibInputStream);
|
1998-07-14 12:06:50 +00:00
|
|
|
};
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxZlibOutputStream: public wxFilterOutputStream {
|
1998-07-14 12:06:50 +00:00
|
|
|
public:
|
2003-12-21 04:28:45 +00:00
|
|
|
wxZlibOutputStream(wxOutputStream& stream, int level = -1, int flags = wxZLIB_ZLIB);
|
2006-10-25 20:45:15 +00:00
|
|
|
wxZlibOutputStream(wxOutputStream *stream, int level = -1, int flags = wxZLIB_ZLIB);
|
2004-11-23 14:26:10 +00:00
|
|
|
virtual ~wxZlibOutputStream() { Close(); }
|
1998-07-14 12:06:50 +00:00
|
|
|
|
2003-09-26 20:07:22 +00:00
|
|
|
void Sync() { DoFlush(false); }
|
2004-11-23 14:26:10 +00:00
|
|
|
bool Close();
|
2004-11-10 21:10:30 +00:00
|
|
|
wxFileOffset GetLength() const { return m_pos; }
|
1998-07-14 12:06:50 +00:00
|
|
|
|
2004-04-11 19:34:56 +00:00
|
|
|
static bool CanHandleGZip();
|
|
|
|
|
2009-03-06 16:26:15 +00:00
|
|
|
bool SetDictionary(const char *data, const size_t datalen);
|
|
|
|
bool SetDictionary(const wxMemoryBuffer &buf);
|
|
|
|
|
1998-07-14 12:06:50 +00:00
|
|
|
protected:
|
1998-10-14 17:36:50 +00:00
|
|
|
size_t OnSysWrite(const void *buffer, size_t size);
|
2004-09-26 13:18:46 +00:00
|
|
|
wxFileOffset OnSysTell() const { return m_pos; }
|
2003-09-26 20:07:22 +00:00
|
|
|
|
|
|
|
virtual void DoFlush(bool final);
|
1998-07-24 17:13:47 +00:00
|
|
|
|
2006-10-25 20:45:15 +00:00
|
|
|
private:
|
|
|
|
void Init(int level, int flags);
|
|
|
|
|
1998-07-24 17:13:47 +00:00
|
|
|
protected:
|
1998-07-14 12:06:50 +00:00
|
|
|
size_t m_z_size;
|
|
|
|
unsigned char *m_z_buffer;
|
1998-09-17 17:30:13 +00:00
|
|
|
struct z_stream_s *m_deflate;
|
2004-09-26 13:18:46 +00:00
|
|
|
wxFileOffset m_pos;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxZlibOutputStream);
|
1998-07-14 12:06:50 +00:00
|
|
|
};
|
|
|
|
|
2006-10-25 20:45:15 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxZlibClassFactory: public wxFilterClassFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxZlibClassFactory();
|
|
|
|
|
|
|
|
wxFilterInputStream *NewStream(wxInputStream& stream) const
|
|
|
|
{ return new wxZlibInputStream(stream); }
|
|
|
|
wxFilterOutputStream *NewStream(wxOutputStream& stream) const
|
|
|
|
{ return new wxZlibOutputStream(stream, -1); }
|
|
|
|
wxFilterInputStream *NewStream(wxInputStream *stream) const
|
|
|
|
{ return new wxZlibInputStream(stream); }
|
|
|
|
wxFilterOutputStream *NewStream(wxOutputStream *stream) const
|
|
|
|
{ return new wxZlibOutputStream(stream, -1); }
|
|
|
|
|
|
|
|
const wxChar * const *GetProtocols(wxStreamProtocolType type
|
|
|
|
= wxSTREAM_PROTOCOL) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxZlibClassFactory)
|
|
|
|
};
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxGzipClassFactory: public wxFilterClassFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxGzipClassFactory();
|
|
|
|
|
|
|
|
wxFilterInputStream *NewStream(wxInputStream& stream) const
|
|
|
|
{ return new wxZlibInputStream(stream); }
|
|
|
|
wxFilterOutputStream *NewStream(wxOutputStream& stream) const
|
|
|
|
{ return new wxZlibOutputStream(stream, -1); }
|
|
|
|
wxFilterInputStream *NewStream(wxInputStream *stream) const
|
|
|
|
{ return new wxZlibInputStream(stream); }
|
|
|
|
wxFilterOutputStream *NewStream(wxOutputStream *stream) const
|
|
|
|
{ return new wxZlibOutputStream(stream, -1); }
|
|
|
|
|
|
|
|
const wxChar * const *GetProtocols(wxStreamProtocolType type
|
|
|
|
= wxSTREAM_PROTOCOL) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxGzipClassFactory)
|
|
|
|
};
|
|
|
|
|
1998-07-14 12:06:50 +00:00
|
|
|
#endif
|
1999-06-15 20:21:59 +00:00
|
|
|
// wxUSE_ZLIB && wxUSE_STREAMS
|
1999-01-04 13:52:06 +00:00
|
|
|
|
|
|
|
#endif
|
1999-07-09 15:30:31 +00:00
|
|
|
// _WX_WXZSTREAM_H__
|
|
|
|
|