removed wxGzipStreams (supported by wxZlibStreams now)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26957 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,172 +0,0 @@
|
||||
%
|
||||
% automatically generated by HelpGen $Revision$ from
|
||||
% gzstream.h at 20/Aug/03 18:41:55
|
||||
%
|
||||
|
||||
%
|
||||
% wxGzipInputStream
|
||||
%
|
||||
|
||||
\section{\class{wxGzipInputStream}}\label{wxgzipinputstream}
|
||||
|
||||
A stream filter to decompress gzipped data. The gzip format is specified in
|
||||
RFC-1952.
|
||||
|
||||
A gzip stream can contain the original filename and timestamp of the
|
||||
compressed data. These fields can be obtained using the
|
||||
\helpref{GetName()}{wxgzipinputstreamgetname} and
|
||||
\helpref{GetDateTime()}{wxgzipinputstreamgetdatetime} accessors.
|
||||
|
||||
If the stream turns out not to be a gzip stream (i.e. the signature bytes
|
||||
0x1f, 0x8b are not found), then the constructor unreads the bytes read and
|
||||
sets the stream state to {\it wxSTREAM\_EOF}.
|
||||
|
||||
So given a possibly gzipped stream '{\it maybe\_gzipped}' you can construct
|
||||
a decompressed stream '{\it decompressed}' with something like:
|
||||
|
||||
\begin{verbatim}
|
||||
wxGzipInputStream gzip(maybe_gzipped);
|
||||
wxInputStream *decompressed = &gzip;
|
||||
if (gzip.Eof())
|
||||
decompressed = &maybe_gzipped;
|
||||
|
||||
\end{verbatim}
|
||||
The stream will not read past the end of the gzip data, therefore you
|
||||
can read another gzip entry concatenated by creating another
|
||||
{\it wxGzipInputStream} on the same underlying stream.
|
||||
|
||||
The stream is not seekable, \helpref{SeekI()}{wxinputstreamseeki} returns
|
||||
{\it wxInvalidOffset}. Also \helpref{GetSize()}{wxstreambasegetsize} is
|
||||
not supported, it always returns $0$.
|
||||
|
||||
\wxheading{Derived from}
|
||||
|
||||
\helpref{wxFilterInputStream}{wxfilterinputstream}
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<wx/gzstream.h>
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxGzipOutputStream}{wxgzipoutputstream},
|
||||
\helpref{wxZlibInputStream}{wxzlibinputstream},
|
||||
\helpref{wxInputStream}{wxinputstream}.
|
||||
|
||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||
|
||||
|
||||
\membersection{wxGzipInputStream::wxGzipInputStream}\label{wxgzipinputstreamwxgzipinputstream}
|
||||
|
||||
\func{}{wxGzipInputStream}{\param{wxInputStream\& }{stream}, \param{wxMBConv\& }{conv = wxConvFile}}
|
||||
|
||||
Constructs an object to decompress a gzipped stream.
|
||||
|
||||
The constructor reads the gzip header. If the original file name and timestamp
|
||||
are present, then they can be obtained through the
|
||||
\helpref{GetName()}{wxgzipinputstreamgetname} and
|
||||
\helpref{GetDateTime()}{wxgzipinputstreamgetdatetime} accessors.
|
||||
|
||||
The filename in the header is stored using an 8-bit character set. In a
|
||||
Unicode build {\it conv} is used to translate the filename into Unicode (it
|
||||
has no effect on the stream data). RFC-1952 specifies that the character set
|
||||
should be ISO-8859-1, however the default here is to use {\it wxConvFile}
|
||||
which more closely matches the behaviour of the gzip program. In
|
||||
a non-Unicode build {\it conv} is ignored.
|
||||
|
||||
If the first two bytes are not the gzip signature, then the data is not
|
||||
gzipped after all. The stream state is set to {\it wxSTREAM\_EOF}, and the
|
||||
two bytes are unread so that the underlying stream can be read directly.
|
||||
|
||||
|
||||
\membersection{wxGzipInputStream::\destruct{wxGzipInputStream}}\label{wxgzipinputstreamdtor}
|
||||
|
||||
\func{}{\destruct{wxGzipInputStream}}{\void}
|
||||
|
||||
Destructor.
|
||||
|
||||
|
||||
\membersection{wxGzipInputStream::GetDateTime}\label{wxgzipinputstreamgetdatetime}
|
||||
|
||||
\constfunc{wxDateTime}{GetDateTime}{\void}
|
||||
|
||||
Returns the original modification time of gzipped data, as obtained from the
|
||||
gzip header.
|
||||
|
||||
|
||||
\membersection{wxGzipInputStream::GetName}\label{wxgzipinputstreamgetname}
|
||||
|
||||
\constfunc{wxString}{GetName}{\void}
|
||||
|
||||
Returns the original filename of gzipped data, with any directory components
|
||||
removed.
|
||||
|
||||
|
||||
%
|
||||
% wxGzipOutputStream
|
||||
%
|
||||
|
||||
\section{\class{wxGzipOutputStream}}\label{wxgzipoutputstream}
|
||||
|
||||
A stream filter to compress gzipped data. The gzip format is specified in
|
||||
RFC-1952.
|
||||
|
||||
The stream is not seekable, \helpref{SeekO()}{wxoutputstreamseeko} returns
|
||||
{\it wxInvalidOffset}.
|
||||
|
||||
|
||||
\wxheading{Derived from}
|
||||
|
||||
\helpref{wxFilterOutputStream}{wxfilteroutputstream}
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<wx/gzstream.h>
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxGzipInputStream}{wxgzipinputstream},
|
||||
\helpref{wxZlibOutputStream}{wxzliboutputstream},
|
||||
\helpref{wxOutputStream}{wxoutputstream}.
|
||||
|
||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||
|
||||
|
||||
\membersection{wxGzipOutputStream::wxGzipOutputStream}\label{wxgzipoutputstreamwxgzipoutputstream}
|
||||
|
||||
\func{}{wxGzipOutputStream}{\param{wxOutputStream\& }{stream}, \param{const wxString\& }{originalName = wxEmptyString}, \param{const wxDateTime\& }{originalTime = wxDateTime::Now()}, \param{int }{level = -1}, \param{wxMBConv\& }{conv = wxConvFile}}
|
||||
|
||||
If the {\it originalName} is given, then it is written to the gzip header
|
||||
with any directory components removed. On a Unicode build it is first
|
||||
converted to an 8-bit encoding using {\it conv}. RFC-1952 specifies that
|
||||
the character set should be ISO-8859-1, however the default here is to
|
||||
use {\it wxConvFile} which more closely matches the behaviour of the gzip
|
||||
program. In a non-Unicode build {\it conv} is ignored. {\it conv} has no
|
||||
effect on the stream data.
|
||||
|
||||
If {\it originalTime} is given then it is also written to the gzip header
|
||||
as the timestamp. If omitted the current time is used.
|
||||
|
||||
{\it level} is the compression level. It can be an integer between $0$ (no
|
||||
compression) and $9$ (most compression). $-1$ specifies that the default
|
||||
compression should be used, and is currently equivalent to $6$.
|
||||
|
||||
You can also use the following constants from <wx/zstream.h>:
|
||||
|
||||
\begin{verbatim}
|
||||
// Compression level
|
||||
enum {
|
||||
wxZ_DEFAULT_COMPRESSION = -1,
|
||||
wxZ_NO_COMPRESSION = 0,
|
||||
wxZ_BEST_SPEED = 1,
|
||||
wxZ_BEST_COMPRESSION = 9
|
||||
}
|
||||
\end{verbatim}
|
||||
|
||||
|
||||
\membersection{wxGzipOutputStream::\destruct{wxGzipOutputStream}}\label{wxgzipoutputstreamdtor}
|
||||
|
||||
\func{}{\destruct{wxGzipOutputStream}}{\void}
|
||||
|
||||
Destructor.
|
||||
|
@@ -1,90 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: gzstream.h
|
||||
// Purpose: Streams for Gzip files
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2003 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_GZSTREAM_H__
|
||||
#define _WX_GZSTREAM_H__
|
||||
|
||||
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
||||
#pragma interface "gzstream.h"
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if wxUSE_STREAMS && wxUSE_GZSTREAM && wxUSE_ZLIB
|
||||
|
||||
#include "wx/datetime.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxGzipInputStream
|
||||
|
||||
class WXDLLIMPEXP_BASE wxGzipInputStream : public wxFilterInputStream
|
||||
{
|
||||
public:
|
||||
wxGzipInputStream(wxInputStream& stream, wxMBConv& conv = wxConvFile);
|
||||
virtual ~wxGzipInputStream();
|
||||
|
||||
wxString GetName() const { return m_name; }
|
||||
|
||||
#if wxUSE_DATETIME
|
||||
wxDateTime GetDateTime() const { return m_datetime; }
|
||||
#endif
|
||||
|
||||
virtual char Peek() { return wxInputStream::Peek(); }
|
||||
virtual size_t GetSize() const { return m_decomp ? m_decomp->GetSize() : 0; }
|
||||
|
||||
protected:
|
||||
virtual size_t OnSysRead(void *buffer, size_t size);
|
||||
virtual off_t OnSysTell() const { return m_decomp ? m_decomp->TellI() : 0; }
|
||||
|
||||
private:
|
||||
wxInputStream *m_decomp;
|
||||
wxUint32 m_crc;
|
||||
wxString m_name;
|
||||
|
||||
#if wxUSE_DATETIME
|
||||
wxDateTime m_datetime;
|
||||
#endif
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxGzipInputStream)
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxGzipOutputStream
|
||||
|
||||
class WXDLLIMPEXP_BASE wxGzipOutputStream : public wxFilterOutputStream
|
||||
{
|
||||
public:
|
||||
wxGzipOutputStream(wxOutputStream& stream,
|
||||
const wxString& originalName = wxEmptyString,
|
||||
#if wxUSE_DATETIME
|
||||
const wxDateTime& originalTime = wxDateTime::Now(),
|
||||
#endif
|
||||
int level = -1,
|
||||
wxMBConv& conv = wxConvFile);
|
||||
virtual ~wxGzipOutputStream();
|
||||
|
||||
virtual void Sync();
|
||||
|
||||
protected:
|
||||
virtual size_t OnSysWrite(const void *buffer, size_t size);
|
||||
virtual off_t OnSysTell() const { return m_comp ? m_comp->TellO() : 0; }
|
||||
|
||||
private:
|
||||
wxOutputStream *m_comp;
|
||||
wxUint32 m_crc;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxGzipOutputStream)
|
||||
};
|
||||
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_GZSTREAM && wxUSE_ZLIB
|
||||
|
||||
#endif // _WX_GZSTREAM_H__
|
@@ -1,294 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: gzstream.cpp
|
||||
// Purpose: Streams for Gzip files
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2003 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
||||
#pragma implementation "gzstream.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS && wxUSE_GZSTREAM && wxUSE_ZLIB
|
||||
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/datstrm.h"
|
||||
#include "wx/txtstrm.h"
|
||||
#include "wx/filename.h"
|
||||
#include "wx/zstream.h"
|
||||
#include "wx/gzstream.h"
|
||||
|
||||
#if defined(__WXMSW__) && !defined(__WX_SETUP_H__) && !defined(wxUSE_ZLIB_H_IN_PATH)
|
||||
#include "../zlib/zlib.h"
|
||||
#else
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Notes:
|
||||
//
|
||||
// See RFC-1952 and the Gzip/Zlib sources for the details of the Gzip format
|
||||
//
|
||||
// Errors are displayed with wxLogError, but not errors from the compressor
|
||||
// or underlying stream, since they will display their own errors.
|
||||
//
|
||||
// Gzip doesn't use flag 2 to indicate a header crc, so I think it's
|
||||
// probably better not to use it for the moment.
|
||||
//
|
||||
|
||||
// Flags
|
||||
enum {
|
||||
GZ_ASCII_FLAG = 0x01,
|
||||
GZ_HEAD_CRC = 0x02,
|
||||
GZ_EXTRA_FIELD = 0x04,
|
||||
GZ_ORIG_NAME = 0x08,
|
||||
GZ_COMMENT = 0x10,
|
||||
GZ_RESERVED = 0xE0
|
||||
};
|
||||
|
||||
// Extra flags
|
||||
enum {
|
||||
GZ_SLOWEST = 2,
|
||||
GZ_FASTEST = 4
|
||||
};
|
||||
|
||||
const wxUint16 GZ_MAGIC = 0x8b1f;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Input stream
|
||||
|
||||
wxGzipInputStream::wxGzipInputStream(wxInputStream& stream,
|
||||
wxMBConv& conv /*=wxConvFile*/)
|
||||
: wxFilterInputStream(stream)
|
||||
{
|
||||
m_decomp = NULL;
|
||||
m_crc = crc32(0, Z_NULL, 0);
|
||||
|
||||
// Try to read the Gzip magic numbers 0x1f, 0x8b. If not found then the
|
||||
// underlying stream isn't gzipped after all, so unread the bytes taken
|
||||
// so that the underlying stream can be read directly instead.
|
||||
wxUint8 magic[2];
|
||||
size_t n = m_parent_i_stream->Read(magic, sizeof(magic)).LastRead();
|
||||
|
||||
if (n < sizeof(magic) || ((magic[1] << 8) | magic[0]) != GZ_MAGIC) {
|
||||
if (n)
|
||||
m_parent_i_stream->Ungetch(magic, n);
|
||||
// Set EOF rather than error to indicate no gzip data
|
||||
m_lasterror = wxSTREAM_EOF;
|
||||
return;
|
||||
}
|
||||
|
||||
wxDataInputStream ds(*m_parent_i_stream);
|
||||
|
||||
// read method, flags, timestamp, extra flags and OS-code
|
||||
int method = ds.Read8();
|
||||
int flags = ds.Read8();
|
||||
#if wxUSE_DATETIME
|
||||
wxUint32 datetime = ds.Read32();
|
||||
if (datetime) // zero means not set (not -1 as usual for time_t)
|
||||
m_datetime = wxLongLong(0, datetime) * 1000L;
|
||||
#else
|
||||
ds.Read32();
|
||||
#endif
|
||||
ds.Read8();
|
||||
ds.Read8();
|
||||
|
||||
if (flags & GZ_HEAD_CRC)
|
||||
ds.Read16();
|
||||
|
||||
if (flags & GZ_EXTRA_FIELD)
|
||||
for (int i = ds.Read16(); i > 0 && m_parent_i_stream->IsOk(); i--)
|
||||
m_parent_i_stream->GetC();
|
||||
|
||||
// RFC-1952 specifies ISO-8859-1 for these fields
|
||||
if (flags & GZ_ORIG_NAME) {
|
||||
#if wxUSE_UNICODE
|
||||
wxTextInputStream tis(*m_parent_i_stream, wxT(" \t"), conv);
|
||||
#else
|
||||
wxTextInputStream tis(*m_parent_i_stream);
|
||||
(void)conv;
|
||||
#endif
|
||||
wxChar c;
|
||||
while ((c = tis.GetChar()) != 0 && m_parent_i_stream->IsOk())
|
||||
m_name += c;
|
||||
}
|
||||
|
||||
if (flags & GZ_COMMENT)
|
||||
while (m_parent_i_stream->GetC() != 0 && m_parent_i_stream->IsOk())
|
||||
; // empty loop
|
||||
|
||||
m_lasterror = wxSTREAM_READ_ERROR;
|
||||
if (!*m_parent_i_stream) {
|
||||
wxLogDebug(wxT("Error reading Gzip header"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (flags & GZ_RESERVED)
|
||||
wxLogWarning(_("Unsupported flag in Gzip header"));
|
||||
|
||||
switch (method) {
|
||||
case Z_DEFLATED:
|
||||
m_decomp = new wxZlibInputStream(*m_parent_i_stream, wxZLIB_NO_HEADER);
|
||||
break;
|
||||
|
||||
default:
|
||||
wxLogError(_("unsupported compression method in Gzip stream"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_decomp)
|
||||
m_lasterror = m_decomp->GetLastError();
|
||||
}
|
||||
|
||||
|
||||
wxGzipInputStream::~wxGzipInputStream()
|
||||
{
|
||||
delete m_decomp;
|
||||
}
|
||||
|
||||
|
||||
size_t wxGzipInputStream::OnSysRead(void *buffer, size_t size)
|
||||
{
|
||||
wxASSERT_MSG(m_decomp, wxT("Gzip not open"));
|
||||
|
||||
if (!m_decomp)
|
||||
m_lasterror = wxSTREAM_READ_ERROR;
|
||||
if (!IsOk() || !size)
|
||||
return 0;
|
||||
|
||||
m_decomp->Read(buffer, size);
|
||||
m_crc = crc32(m_crc, (Byte*)buffer, m_decomp->LastRead());
|
||||
|
||||
if (m_decomp->Eof()) {
|
||||
wxDataInputStream ds(*m_parent_i_stream);
|
||||
m_lasterror = wxSTREAM_READ_ERROR;
|
||||
|
||||
if (m_parent_i_stream->IsOk()) {
|
||||
if (ds.Read32() != m_crc)
|
||||
wxLogError(_("reading Gzip stream: bad crc"));
|
||||
else if (ds.Read32() != (wxUint32)TellI())
|
||||
wxLogError(_("reading Gzip stream: incorrect length"));
|
||||
else
|
||||
m_lasterror = wxSTREAM_EOF;
|
||||
}
|
||||
}
|
||||
else if (!*m_decomp) {
|
||||
m_lasterror = wxSTREAM_READ_ERROR;
|
||||
}
|
||||
|
||||
return m_decomp->LastRead();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Output stream
|
||||
|
||||
wxGzipOutputStream::wxGzipOutputStream(
|
||||
wxOutputStream& stream,
|
||||
const wxString& originalName /*=wxEmptyString*/,
|
||||
#if wxUSE_DATETIME
|
||||
const wxDateTime& originalTime /*=wxDateTime::Now()*/,
|
||||
#endif
|
||||
int level /*=-1*/,
|
||||
wxMBConv& conv /*=wxConvFile*/)
|
||||
: wxFilterOutputStream(stream)
|
||||
{
|
||||
m_comp = NULL;
|
||||
m_crc = crc32(0, Z_NULL, 0);
|
||||
|
||||
wxFileName filename(originalName);
|
||||
|
||||
wxUint32 timestamp = 0;
|
||||
#if wxUSE_DATETIME
|
||||
if (originalTime.IsValid())
|
||||
timestamp = (originalTime.GetValue() / 1000L).GetLo();
|
||||
#endif
|
||||
|
||||
// RFC-1952 specifies ISO-8859-1 for the name. Also it should be just the
|
||||
// name part, no directory, folded to lowercase if case insensitive
|
||||
wxString name = filename.GetFullName();
|
||||
const wxWX2MBbuf mbName = conv.cWX2MB(name);
|
||||
|
||||
wxDataOutputStream ds(*m_parent_o_stream);
|
||||
|
||||
// write signature, method, flags, timestamp, extra flags and OS-code
|
||||
ds.Write16(GZ_MAGIC);
|
||||
ds.Write8(Z_DEFLATED);
|
||||
ds.Write8(mbName && *mbName ? GZ_ORIG_NAME : 0);
|
||||
ds.Write32(timestamp);
|
||||
ds.Write8(level == 1 ? GZ_FASTEST : level == 9 ? GZ_SLOWEST : 0);
|
||||
ds.Write8(255);
|
||||
|
||||
if (mbName && *mbName)
|
||||
m_parent_o_stream->Write(mbName, strlen(mbName) + 1);
|
||||
|
||||
m_lasterror = wxSTREAM_WRITE_ERROR;
|
||||
if (!*m_parent_o_stream) {
|
||||
wxLogDebug(wxT("Error writing Gzip header"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_comp = new wxZlibOutputStream(*m_parent_o_stream, level, wxZLIB_NO_HEADER);
|
||||
|
||||
if (m_comp)
|
||||
m_lasterror = m_comp->GetLastError();
|
||||
}
|
||||
|
||||
|
||||
wxGzipOutputStream::~wxGzipOutputStream()
|
||||
{
|
||||
if (m_comp && m_comp->IsOk()) {
|
||||
wxUint32 len = (wxUint32)m_comp->TellO();
|
||||
delete m_comp;
|
||||
if (m_parent_o_stream->IsOk()) {
|
||||
wxDataOutputStream ds(*m_parent_o_stream);
|
||||
ds.Write32(m_crc);
|
||||
ds.Write32(len); // underlying stream will report errors
|
||||
}
|
||||
} else {
|
||||
delete m_comp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxGzipOutputStream::Sync()
|
||||
{
|
||||
wxASSERT_MSG(m_comp, wxT("Gzip not open"));
|
||||
|
||||
if (!m_comp)
|
||||
m_lasterror = wxSTREAM_WRITE_ERROR;
|
||||
if (IsOk())
|
||||
m_comp->Sync();
|
||||
}
|
||||
|
||||
|
||||
size_t wxGzipOutputStream::OnSysWrite(const void *buffer, size_t size)
|
||||
{
|
||||
wxASSERT_MSG(m_comp, wxT("Gzip not open"));
|
||||
|
||||
if (!m_comp)
|
||||
m_lasterror = wxSTREAM_WRITE_ERROR;
|
||||
if (!IsOk() || !size)
|
||||
return 0;
|
||||
|
||||
if (m_comp->Write(buffer, size).LastWrite() != size)
|
||||
m_lasterror = wxSTREAM_WRITE_ERROR;
|
||||
m_crc = crc32(m_crc, (Byte*)buffer, size);
|
||||
|
||||
return m_comp->LastWrite();
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_GZSTREAM && wxUSE_ZLIB
|
Reference in New Issue
Block a user