Rizin
unix-like reverse engineering framework and cli tools
zfstream.h
Go to the documentation of this file.
1 
2 #ifndef zfstream_h
3 #define zfstream_h
4 
5 #include <fstream.h>
6 #include "zlib.h"
7 
8 class gzfilebuf : public streambuf {
9 
10 public:
11 
12  gzfilebuf( );
13  virtual ~gzfilebuf();
14 
15  gzfilebuf *open( const char *name, int io_mode );
16  gzfilebuf *attach( int file_descriptor, int io_mode );
17  gzfilebuf *close();
18 
19  int setcompressionlevel( int comp_level );
20  int setcompressionstrategy( int comp_strategy );
21 
22  inline int is_open() const { return (file !=NULL); }
23 
24  virtual streampos seekoff( streamoff, ios::seek_dir, int );
25 
26  virtual int sync();
27 
28 protected:
29 
30  virtual int underflow();
31  virtual int overflow( int = EOF );
32 
33 private:
34 
36  short mode;
38 
39  int flushbuf();
40  int fillbuf();
41 
42 };
43 
44 class gzfilestream_common : virtual public ios {
45 
46  friend class gzifstream;
47  friend class gzofstream;
48  friend gzofstream &setcompressionlevel( gzofstream &, int );
50 
51 public:
52  virtual ~gzfilestream_common();
53 
54  void attach( int fd, int io_mode );
55  void open( const char *name, int io_mode );
56  void close();
57 
58 protected:
60 
61 private:
62  gzfilebuf *rdbuf();
63 
65 
66 };
67 
68 class gzifstream : public gzfilestream_common, public istream {
69 
70 public:
71 
72  gzifstream();
73  gzifstream( const char *name, int io_mode = ios::in );
74  gzifstream( int fd, int io_mode = ios::in );
75 
76  virtual ~gzifstream();
77 
78 };
79 
80 class gzofstream : public gzfilestream_common, public ostream {
81 
82 public:
83 
84  gzofstream();
85  gzofstream( const char *name, int io_mode = ios::out );
86  gzofstream( int fd, int io_mode = ios::out );
87 
88  virtual ~gzofstream();
89 
90 };
91 
92 template<class T> class gzomanip {
93  friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &);
94 public:
95  gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { }
96 private:
97  gzofstream &(*func)(gzofstream &, T);
98  T val;
99 };
100 
101 template<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m)
102 {
103  return (*m.func)(s, m.val);
104 }
105 
107 {
108  (s.rdbuf())->setcompressionlevel(l);
109  return s;
110 }
111 
113 {
114  (s.rdbuf())->setcompressionstrategy(l);
115  return s;
116 }
117 
119 {
121 }
122 
124 {
126 }
127 
128 #endif
#define T(op)
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
Gzipped file stream buffer class.
Definition: zfstream.h:8
virtual streampos seekoff(streamoff, ios::seek_dir, int)
Definition: zfstream.cpp:129
gzfilebuf * close()
Definition: zfstream.cpp:102
gzFile file
Definition: zfstream.h:35
virtual int underflow()
Definition: zfstream.cpp:135
std::ios_base::openmode io_mode
Definition: zfstream.h:191
gzfilebuf * attach(int file_descriptor, int io_mode)
Definition: zfstream.cpp:60
int setcompressionstrategy(int comp_strategy)
Definition: zfstream.cpp:122
short mode
Definition: zfstream.h:36
virtual ~gzfilebuf()
Definition: zfstream.cpp:10
virtual int overflow(int=EOF)
Definition: zfstream.cpp:173
int setcompressionlevel(int comp_level)
Definition: zfstream.cpp:116
gzfilebuf()
Definition: zfstream.cpp:4
int flushbuf()
Definition: zfstream.cpp:218
int fillbuf()
Definition: zfstream.cpp:235
gzfilebuf * open(const char *name, int io_mode)
Definition: zfstream.cpp:18
virtual int sync()
Definition: zfstream.cpp:206
int is_open() const
Definition: zfstream.h:22
short own_file_descriptor
Definition: zfstream.h:37
friend gzofstream & setcompressionlevel(gzofstream &, int)
Definition: zfstream.h:106
friend gzofstream & setcompressionstrategy(gzofstream &, int)
Definition: zfstream.h:112
void attach(int fd, int io_mode)
Definition: zfstream.cpp:261
void open(const char *name, int io_mode)
Definition: zfstream.cpp:270
gzfilebuf * rdbuf()
Definition: zfstream.cpp:286
gzfilebuf buffer
Definition: zfstream.h:64
virtual ~gzfilestream_common()
Definition: zfstream.cpp:258
Gzipped file input stream class.
Definition: zfstream.h:68
virtual ~gzifstream()
Definition: zfstream.cpp:309
Gzipped file output stream class.
Definition: zfstream.h:80
virtual ~gzofstream()
Definition: zfstream.cpp:329
gzomanip(gzofstream &(*f)(gzofstream &, T), T v)
Definition: zfstream.h:95
gzofstream &(* func)(gzofstream &, T)
Definition: zfstream.h:97
friend gzofstream & operator<<(gzofstream &, const gzomanip< T > &)
Definition: zfstream.h:101
#define NULL
Definition: cris-opc.c:27
const char * v
Definition: dsignal.c:12
gzofstream & operator<<(gzofstream &s, const gzomanip< T > &m)
Definition: zfstream.h:101
gzofstream & setcompressionstrategy(gzofstream &s, int l)
Definition: zfstream.h:112
gzofstream & setcompressionlevel(gzofstream &s, int l)
Definition: zfstream.h:106
static RzSocket * s
Definition: rtr.c:28
#define f(i)
Definition: sha256.c:46
Definition: gzappend.c:170
Definition: z80asm.h:102
static const z80_opcode fd[]
Definition: z80_tab.h:997