File indexing completed on 2025-04-19 09:09:52
0001 #ifndef ATOOLS_Org_Gzip_Stream_H
0002 #define ATOOLS_Org_Gzip_Stream_H
0003
0004
0005
0006
0007
0008
0009
0010 #include <iostream>
0011 #include <fstream>
0012 #include <zlib.h>
0013
0014 namespace ATOOLS {
0015
0016
0017
0018
0019
0020 class gzstreambuf : public std::streambuf {
0021 private:
0022 static const int bufferSize = 47+256;
0023
0024
0025 gzFile file;
0026 char buffer[bufferSize];
0027 char opened;
0028 int mode;
0029
0030 int flush_buffer();
0031 public:
0032 gzstreambuf() : opened(0) {
0033 setp( buffer, buffer + (bufferSize-1));
0034 setg( buffer + 4,
0035 buffer + 4,
0036 buffer + 4);
0037
0038 }
0039 int is_open() { return opened; }
0040 gzstreambuf* open( const char* name, int open_mode);
0041 gzstreambuf* close();
0042 ~gzstreambuf() { close(); }
0043
0044 virtual int overflow( int c = EOF);
0045 virtual int underflow();
0046 virtual int sync();
0047 };
0048
0049 class gzstreambase : virtual public std::ios {
0050 protected:
0051 gzstreambuf buf;
0052 public:
0053 gzstreambase() { init(&buf); }
0054 gzstreambase( const char* name, int open_mode);
0055 ~gzstreambase();
0056 void open( const char* name, int open_mode);
0057 void close();
0058 gzstreambuf* rdbuf() { return &buf; }
0059 };
0060
0061
0062
0063
0064
0065
0066
0067 class igzstream : public gzstreambase, public std::istream {
0068 public:
0069 igzstream() : std::istream( &buf) {}
0070 igzstream( const char* name, int open_mode = std::ios::in)
0071 : gzstreambase( name, open_mode), std::istream( &buf) {}
0072 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
0073 void open( const char* name, int open_mode = std::ios::in) {
0074 gzstreambase::open( name, open_mode);
0075 }
0076 };
0077
0078 class ogzstream : public gzstreambase, public std::ostream {
0079 public:
0080 ogzstream() : std::ostream( &buf) {}
0081 ogzstream( const char* name, int mode = std::ios::out)
0082 : gzstreambase( name, mode), std::ostream( &buf) {}
0083 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
0084 void open( const char* name, int open_mode = std::ios::out) {
0085 gzstreambase::open( name, open_mode);
0086 }
0087 };
0088
0089 }
0090
0091 #endif
0092