1 // A C++ I/O streams interface to the zlib gz* functions
3 // Written by Bernie Bright, 1998
4 // Based on zlib/contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
6 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 // (Log is kept at end of this file)
28 #include "zlib/zlib.h"
29 #include "Include/compiler.h"
31 #ifdef FG_HAVE_STD_INCLUDES
36 # define ios_openmode ios_base::openmode
37 # define ios_in ios_base::in
38 # define ios_out ios_base::out
39 # define ios_app ios_base::app
40 # define ios_binary ios_base::binary
42 # define ios_seekdir ios_base::seekdir
44 # define ios_badbit ios_base::badbit
45 # define ios_failbit ios_base::failbit
47 FG_USING_STD(streambuf);
48 FG_USING_STD(ios_base);
49 FG_USING_STD(streampos);
50 FG_USING_STD(streamoff);
54 # ifdef FG_HAVE_STREAMBUF
55 # include <streambuf.h>
58 # include <iostream.h>
61 //# define ios_openmode ios::open_mode
62 # define ios_openmode int
63 # define ios_in ios::in
64 # define ios_out ios::out
65 # define ios_app ios::app
67 #if defined(__GNUC__) && __GNUC_MINOR__ < 8
68 # define ios_binary ios::bin
70 # define ios_binary ios::binary
73 # define ios_seekdir ios::seek_dir
75 # define ios_badbit ios::badbit
76 # define ios_failbit ios::failbit
78 # include "Include/fg_traits.hxx"
80 #endif // FG_HAVE_STD_INCLUDES
82 //-----------------------------------------------------------------------------
86 class gzfilebuf : public streambuf
90 #ifndef FG_HAVE_STD_INCLUDES
91 typedef char_traits<char> traits_type;
92 typedef char_traits<char>::int_type int_type;
93 typedef char_traits<char>::pos_type pos_type;
94 typedef char_traits<char>::off_type off_type;
100 gzfilebuf* open( const char* name, ios_openmode io_mode );
101 gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
104 // int setcompressionlevel( int comp_level );
105 // int setcompressionstrategy( int comp_strategy );
106 bool is_open() const { return (file != NULL); }
107 virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
112 virtual int_type underflow();
113 virtual int_type overflow( int_type c = traits_type::eof() );
120 // Convert io_mode to "rwab" string.
121 void cvt_iomode( char* mode_str, ios_openmode io_mode );
127 bool own_file_descriptor;
129 // Get (input) buffer.
133 enum { page_size = 4096 };
137 gzfilebuf( const gzfilebuf& );
138 void operator= ( const gzfilebuf& );
141 //-----------------------------------------------------------------------------
145 struct gzifstream_base
152 #endif // _zfstream_hxx
155 // Revision 1.7 1999/01/19 20:41:49 curt
156 // Portability updates contributed by Bernie Bright.
158 // Revision 1.6 1998/12/07 21:10:26 curt
159 // Portability improvements.
161 // Revision 1.5 1998/11/06 21:17:29 curt
162 // Converted to new logstream debugging facility. This allows release
163 // builds with no messages at all (and no performance impact) by using
164 // the -DFG_NDEBUG flag.
166 // Revision 1.4 1998/11/06 14:05:16 curt
167 // More portability improvements by Bernie Bright.