1998-11-06 22:05:12 +08:00
|
|
|
// A C++ I/O streams interface to the zlib gz* functions
|
|
|
|
//
|
|
|
|
// Written by Bernie Bright, 1998
|
|
|
|
// Based on zlib/contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
1998-09-02 03:06:28 +08:00
|
|
|
|
|
|
|
#ifndef _zfstream_hxx
|
|
|
|
#define _zfstream_hxx
|
|
|
|
|
|
|
|
#include "zlib/zlib.h"
|
1998-11-06 22:05:12 +08:00
|
|
|
#include "Include/compiler.h"
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
#ifdef FG_HAVE_STD_INCLUDES
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# include <streambuf>
|
|
|
|
# include <istream>
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# define ios_openmode ios_base::openmode
|
|
|
|
# define ios_in ios_base::in
|
|
|
|
# define ios_out ios_base::out
|
|
|
|
# define ios_app ios_base::app
|
|
|
|
# define ios_binary ios_base::binary
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# define ios_seekdir ios_base::seekdir
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# define ios_badbit ios_base::badbit
|
|
|
|
# define ios_failbit ios_base::failbit
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1999-01-20 04:41:46 +08:00
|
|
|
FG_USING_STD(streambuf);
|
|
|
|
FG_USING_STD(ios_base);
|
|
|
|
FG_USING_STD(streampos);
|
|
|
|
FG_USING_STD(streamoff);
|
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
#else
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# ifdef FG_HAVE_STREAMBUF
|
|
|
|
# include <streambuf.h>
|
|
|
|
# include <istream.h>
|
|
|
|
# else
|
|
|
|
# include <iostream.h>
|
|
|
|
# endif
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
//# define ios_openmode ios::open_mode
|
|
|
|
# define ios_openmode int
|
|
|
|
# define ios_in ios::in
|
|
|
|
# define ios_out ios::out
|
|
|
|
# define ios_app ios::app
|
1998-12-08 05:10:26 +08:00
|
|
|
|
|
|
|
#if defined(__GNUC__) && __GNUC_MINOR__ < 8
|
|
|
|
# define ios_binary ios::bin
|
1999-02-27 06:07:53 +08:00
|
|
|
#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS )
|
1999-03-09 06:00:12 +08:00
|
|
|
# define ios_binary 0
|
1998-12-08 05:10:26 +08:00
|
|
|
#else
|
1998-11-06 22:05:12 +08:00
|
|
|
# define ios_binary ios::binary
|
1998-12-08 05:10:26 +08:00
|
|
|
#endif
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# define ios_seekdir ios::seek_dir
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
# define ios_badbit ios::badbit
|
|
|
|
# define ios_failbit ios::failbit
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-07 05:17:23 +08:00
|
|
|
# include "Include/fg_traits.hxx"
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
#endif // FG_HAVE_STD_INCLUDES
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
class gzfilebuf : public streambuf
|
|
|
|
{
|
1998-09-02 03:06:28 +08:00
|
|
|
public:
|
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
#ifndef FG_HAVE_STD_INCLUDES
|
|
|
|
typedef char_traits<char> traits_type;
|
|
|
|
typedef char_traits<char>::int_type int_type;
|
|
|
|
typedef char_traits<char>::pos_type pos_type;
|
|
|
|
typedef char_traits<char>::off_type off_type;
|
|
|
|
#endif
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
gzfilebuf();
|
|
|
|
virtual ~gzfilebuf();
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
gzfilebuf* open( const char* name, ios_openmode io_mode );
|
|
|
|
gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
|
|
|
|
gzfilebuf* close();
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
// int setcompressionlevel( int comp_level );
|
|
|
|
// int setcompressionstrategy( int comp_strategy );
|
|
|
|
bool is_open() const { return (file != NULL); }
|
|
|
|
virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
|
|
|
|
virtual int sync();
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
protected:
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
virtual int_type underflow();
|
|
|
|
virtual int_type overflow( int_type c = traits_type::eof() );
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
private:
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
int_type flushbuf();
|
|
|
|
int fillbuf();
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
// Convert io_mode to "rwab" string.
|
|
|
|
void cvt_iomode( char* mode_str, ios_openmode io_mode );
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
private:
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
gzFile file;
|
|
|
|
ios_openmode mode;
|
|
|
|
bool own_file_descriptor;
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
// Get (input) buffer.
|
|
|
|
int ibuf_size;
|
|
|
|
char* ibuffer;
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1999-01-20 04:41:46 +08:00
|
|
|
enum { page_size = 4096 };
|
1998-09-02 03:06:28 +08:00
|
|
|
|
|
|
|
private:
|
1998-11-06 22:05:12 +08:00
|
|
|
// Not defined
|
|
|
|
gzfilebuf( const gzfilebuf& );
|
|
|
|
void operator= ( const gzfilebuf& );
|
1998-09-02 03:06:28 +08:00
|
|
|
};
|
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
struct gzifstream_base
|
1998-09-02 03:06:28 +08:00
|
|
|
{
|
1998-11-06 22:05:12 +08:00
|
|
|
gzifstream_base() {}
|
1998-09-02 03:06:28 +08:00
|
|
|
|
1998-11-06 22:05:12 +08:00
|
|
|
gzfilebuf gzbuf;
|
|
|
|
};
|
1998-09-02 03:06:28 +08:00
|
|
|
|
|
|
|
#endif // _zfstream_hxx
|
1998-11-06 22:05:12 +08:00
|
|
|
|