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