Rizin
unix-like reverse engineering framework and cli tools
gzfilebuf Class Reference

Gzipped file stream buffer class. More...

#include <zfstream.h>

Inheritance diagram for gzfilebuf:

Public Member Functions

 gzfilebuf ()
 
virtual ~gzfilebuf ()
 
gzfilebufopen (const char *name, int io_mode)
 
gzfilebufattach (int file_descriptor, int io_mode)
 
gzfilebufclose ()
 
int setcompressionlevel (int comp_level)
 
int setcompressionstrategy (int comp_strategy)
 
int is_open () const
 
virtual streampos seekoff (streamoff, ios::seek_dir, int)
 
virtual int sync ()
 
 gzfilebuf ()
 
virtual ~gzfilebuf ()
 
int setcompression (int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY)
 Set compression level and strategy on the fly. More...
 
bool is_open () const
 Check if file is open. More...
 
gzfilebufopen (const char *name, std::ios_base::openmode mode)
 Open gzipped file. More...
 
gzfilebufattach (int fd, std::ios_base::openmode mode)
 Attach to already open gzipped file. More...
 
gzfilebufclose ()
 Close gzipped file. More...
 

Protected Member Functions

virtual int underflow ()
 
virtual int overflow (int=EOF)
 
bool open_mode (std::ios_base::openmode mode, char *c_mode) const
 Convert ios open mode int to mode string used by zlib. More...
 
virtual std::streamsize showmanyc ()
 Number of characters available in stream buffer. More...
 
virtual int_type underflow ()
 Fill get area from gzipped file. More...
 
virtual int_type overflow (int_type c=traits_type::eof())
 Write put area to gzipped file. More...
 
virtual std::streambuf * setbuf (char_type *p, std::streamsize n)
 Installs external stream buffer. More...
 
virtual int sync ()
 Flush stream buffer to file. More...
 

Private Member Functions

int flushbuf ()
 
int fillbuf ()
 
void enable_buffer ()
 Allocate internal buffer. More...
 
void disable_buffer ()
 Destroy internal buffer. More...
 

Private Attributes

gzFile file
 
short mode
 
short own_file_descriptor
 
std::ios_base::openmode io_mode
 
bool own_fd
 True if this object owns file descriptor. More...
 
char_type * buffer
 Stream buffer. More...
 
std::streamsize buffer_size
 Stream buffer size. More...
 
bool own_buffer
 True if this object owns stream buffer. More...
 

Detailed Description

Gzipped file stream buffer class.

This class implements basic_filebuf for gzipped files. It doesn't yet support seeking (allowed by zlib but slow/limited), putback and read/write access (tricky). Otherwise, it attempts to be a drop-in replacement for the standard file streambuf.

Definition at line 8 of file zfstream.h.

Constructor & Destructor Documentation

◆ gzfilebuf() [1/2]

gzfilebuf::gzfilebuf ( )

Definition at line 4 of file zfstream.cpp.

4  :
5  file(NULL),
6  mode(0),
8 { }
gzFile file
Definition: zfstream.h:35
short mode
Definition: zfstream.h:36
short own_file_descriptor
Definition: zfstream.h:37
#define NULL
Definition: cris-opc.c:27

◆ ~gzfilebuf() [1/2]

gzfilebuf::~gzfilebuf ( )
virtual

Definition at line 10 of file zfstream.cpp.

10  {
11 
12  sync();
13  if ( own_file_descriptor )
14  close();
15 
16 }
gzfilebuf * close()
Definition: zfstream.cpp:102
virtual int sync()
Definition: zfstream.cpp:206

References close(), own_file_descriptor, and sync().

◆ gzfilebuf() [2/2]

gzfilebuf::gzfilebuf ( )

◆ ~gzfilebuf() [2/2]

virtual gzfilebuf::~gzfilebuf ( )
virtual

Member Function Documentation

◆ attach() [1/2]

gzfilebuf * gzfilebuf::attach ( int  fd,
std::ios_base::openmode  mode 
)

Attach to already open gzipped file.

Parameters
fdFile descriptor.
modeOpen mode flags.
Returns
this on success, NULL on failure.

Definition at line 79 of file zfstream.cc.

81 {
82  // Fail if file already open
83  if (this->is_open())
84  return NULL;
85  // Don't support simultaneous read/write access (yet)
87  return NULL;
88 
89  // Build mode string for gzdopen and check it [27.8.1.3.2]
90  char char_mode[6] = "\0\0\0\0\0";
91  if (!this->open_mode(mode, char_mode))
92  return NULL;
93 
94  // Attempt to attach to file
95  if ((file = gzdopen(fd, char_mode)) == NULL)
96  return NULL;
97 
98  // On success, allocate internal buffer and set flags
99  this->enable_buffer();
100  io_mode = mode;
101  own_fd = false;
102  return this;
103 }
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
std::ios_base::openmode io_mode
Definition: zfstream.h:191
bool own_fd
True if this object owns file descriptor.
Definition: zfstream.h:199
bool open_mode(std::ios_base::openmode mode, char *c_mode) const
Convert ios open mode int to mode string used by zlib.
Definition: zfstream.cc:131
void enable_buffer()
Allocate internal buffer.
Definition: zfstream.cc:308
int is_open() const
Definition: zfstream.h:22
gzFile ZEXPORT gzdopen(int fd, const char *mode)
Definition: gzlib.c:288
const char int mode
Definition: ioapi.h:137
Definition: gzappend.c:170
static const z80_opcode fd[]
Definition: z80_tab.h:997

References enable_buffer(), fd, gzdopen(), in, io_mode, is_open(), mode, NULL, open_mode(), out, and own_fd.

◆ attach() [2/2]

gzfilebuf * gzfilebuf::attach ( int  file_descriptor,
int  io_mode 
)

Definition at line 60 of file zfstream.cpp.

61  {
62 
63  if ( is_open() )
64  return NULL;
65 
66  char char_mode[10];
67  char *p = char_mode;
68 
69  if ( io_mode & ios::in ) {
70  mode = ios::in;
71  *p++ = 'r';
72  } else if ( io_mode & ios::app ) {
73  mode = ios::app;
74  *p++ = 'a';
75  } else {
76  mode = ios::out;
77  *p++ = 'w';
78  }
79 
80  if ( io_mode & ios::binary ) {
81  mode |= ios::binary;
82  *p++ = 'b';
83  }
84 
85  // Hard code the compression level
86  if ( io_mode & (ios::out|ios::app )) {
87  *p++ = '9';
88  }
89 
90  // Put the end-of-string indicator
91  *p = '\0';
92 
93  if ( (file = gzdopen(file_descriptor, char_mode)) == NULL )
94  return NULL;
95 
97 
98  return this;
99 
100 }
void * p
Definition: libc.cpp:67
static char * binary(unsigned int val, unsigned int bits)
Definition: debug.c:3

References binary(), gzdopen(), in, io_mode, is_open(), NULL, out, own_file_descriptor, and p.

Referenced by gzifstream::attach(), and gzofstream::attach().

◆ close() [1/2]

gzfilebuf * gzfilebuf::close ( )

Definition at line 102 of file zfstream.cpp.

102  {
103 
104  if ( is_open() ) {
105 
106  sync();
107  gzclose( file );
108  file = NULL;
109 
110  }
111 
112  return this;
113 
114 }
int ZEXPORT gzclose(gzFile file)
Definition: gzclose.c:11

References gzclose(), is_open(), NULL, and sync().

Referenced by gzifstream::close(), gzofstream::close(), and ~gzfilebuf().

◆ close() [2/2]

gzfilebuf* gzfilebuf::close ( )

Close gzipped file.

Returns
this on success, NULL on failure.

◆ disable_buffer()

void gzfilebuf::disable_buffer ( )
private

Destroy internal buffer.

This function is safe to call multiple times. It will ensure that the internal buffer is deallocated if it exists. In any case, it will also reset the buffer pointers.

Definition at line 347 of file zfstream.cc.

348 {
349  // If internal buffer exists, deallocate it
350  if (own_buffer && buffer)
351  {
352  // Preserve unbuffered status by zeroing size
353  if (!this->pbase())
354  buffer_size = 0;
355  delete[] buffer;
356  buffer = NULL;
357  this->setg(0, 0, 0);
358  this->setp(0, 0);
359  }
360  else
361  {
362  // Reset buffer pointers to initial state if external buffer exists
363  this->setg(buffer, buffer, buffer);
364  if (buffer)
365  this->setp(buffer, buffer + buffer_size - 1);
366  else
367  this->setp(0, 0);
368  }
369 }
std::streamsize buffer_size
Stream buffer size.
Definition: zfstream.h:215
char_type * buffer
Stream buffer.
Definition: zfstream.h:207
bool own_buffer
True if this object owns stream buffer.
Definition: zfstream.h:223
Definition: buffer.h:15

References buffer, buffer_size, NULL, and own_buffer.

Referenced by setbuf().

◆ enable_buffer()

void gzfilebuf::enable_buffer ( )
private

Allocate internal buffer.

This function is safe to call multiple times. It will ensure that a proper internal buffer exists if it is required. If the buffer already exists or is external, the buffer pointers will be reset to their original state.

Definition at line 308 of file zfstream.cc.

309 {
310  // If internal buffer required, allocate one
311  if (own_buffer && !buffer)
312  {
313  // Check for buffered vs. "unbuffered"
314  if (buffer_size > 0)
315  {
316  // Allocate internal buffer
317  buffer = new char_type[buffer_size];
318  // Get area starts empty and will be expanded by underflow as need arises
319  this->setg(buffer, buffer, buffer);
320  // Setup entire internal buffer as put area.
321  // The one-past-end pointer actually points to the last element of the buffer,
322  // so that overflow(c) can safely add the extra character c to the sequence.
323  // These pointers remain in place for the duration of the buffer
324  this->setp(buffer, buffer + buffer_size - 1);
325  }
326  else
327  {
328  // Even in "unbuffered" case, (small?) get buffer is still required
330  buffer = new char_type[buffer_size];
331  this->setg(buffer, buffer, buffer);
332  // "Unbuffered" means no put buffer
333  this->setp(0, 0);
334  }
335  }
336  else
337  {
338  // If buffer already allocated, reset buffer pointers just to make sure no
339  // stale chars are lying around
340  this->setg(buffer, buffer, buffer);
341  this->setp(buffer, buffer + buffer_size - 1);
342  }
343 }
#define SMALLBUFSIZE
Definition: zfstream.cc:16

References buffer_size, own_buffer, and SMALLBUFSIZE.

Referenced by attach(), open(), and setbuf().

◆ fillbuf()

int gzfilebuf::fillbuf ( )
private

Definition at line 235 of file zfstream.cpp.

235  {
236 
237  int required;
238  char *p;
239 
240  p = base();
241 
242  required = blen();
243 
244  int t = gzread( file, p, required );
245 
246  if ( t <= 0) return EOF;
247 
248  setg( base(), base(), base()+t);
249 
250  return t;
251 
252 }
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
Definition: gzread.c:375

References gzread(), p, and cmd_descs_generate::required.

Referenced by underflow().

◆ flushbuf()

int gzfilebuf::flushbuf ( )
private

Definition at line 218 of file zfstream.cpp.

218  {
219 
220  int n;
221  char *q;
222 
223  q = pbase();
224  n = pptr() - q;
225 
226  if ( gzwrite( file, q, n) < n )
227  return EOF;
228 
229  setp(0,0);
230 
231  return 0;
232 
233 }
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
Definition: gzwrite.c:255
int n
Definition: mipsasm.c:19

References gzwrite(), and n.

Referenced by overflow(), sync(), and underflow().

◆ is_open() [1/2]

int gzfilebuf::is_open ( ) const
inline

Definition at line 22 of file zfstream.h.

22 { return (file !=NULL); }

References NULL.

Referenced by attach(), close(), gzifstream::is_open(), gzofstream::is_open(), open(), overflow(), showmanyc(), sync(), and underflow().

◆ is_open() [2/2]

bool gzfilebuf::is_open ( ) const
inline

Check if file is open.

Returns
True if file is open.

Definition at line 57 of file zfstream.h.

57 { return (file != NULL); }

References NULL.

◆ open() [1/2]

gzfilebuf * gzfilebuf::open ( const char *  name,
int  io_mode 
)

Definition at line 18 of file zfstream.cpp.

19  {
20 
21  if ( is_open() )
22  return NULL;
23 
24  char char_mode[10];
25  char *p = char_mode;
26 
27  if ( io_mode & ios::in ) {
28  mode = ios::in;
29  *p++ = 'r';
30  } else if ( io_mode & ios::app ) {
31  mode = ios::app;
32  *p++ = 'a';
33  } else {
34  mode = ios::out;
35  *p++ = 'w';
36  }
37 
38  if ( io_mode & ios::binary ) {
39  mode |= ios::binary;
40  *p++ = 'b';
41  }
42 
43  // Hard code the compression level
44  if ( io_mode & (ios::out|ios::app )) {
45  *p++ = '9';
46  }
47 
48  // Put the end-of-string indicator
49  *p = '\0';
50 
51  if ( (file = gzopen(name, char_mode)) == NULL )
52  return NULL;
53 
55 
56  return this;
57 
58 }
gzFile ZEXPORT gzopen(char *path, const char *mode) const
Definition: gzlib.c:272
Definition: z80asm.h:102

References binary(), gzopen(), in, io_mode, is_open(), NULL, out, own_file_descriptor, and p.

Referenced by gzifstream::open(), and gzofstream::open().

◆ open() [2/2]

gzfilebuf * gzfilebuf::open ( const char *  name,
std::ios_base::openmode  mode 
)

Open gzipped file.

Parameters
nameFile name.
modeOpen mode flags.
Returns
this on success, NULL on failure.

Definition at line 51 of file zfstream.cc.

53 {
54  // Fail if file already open
55  if (this->is_open())
56  return NULL;
57  // Don't support simultaneous read/write access (yet)
59  return NULL;
60 
61  // Build mode string for gzopen and check it [27.8.1.3.2]
62  char char_mode[6] = "\0\0\0\0\0";
63  if (!this->open_mode(mode, char_mode))
64  return NULL;
65 
66  // Attempt to open file
67  if ((file = gzopen(name, char_mode)) == NULL)
68  return NULL;
69 
70  // On success, allocate internal buffer and set flags
71  this->enable_buffer();
72  io_mode = mode;
73  own_fd = true;
74  return this;
75 }

References enable_buffer(), gzopen(), in, io_mode, is_open(), mode, NULL, open_mode(), out, and own_fd.

◆ open_mode()

bool gzfilebuf::open_mode ( std::ios_base::openmode  mode,
char *  c_mode 
) const
protected

Convert ios open mode int to mode string used by zlib.

Returns
True if valid mode flag combination.

Definition at line 131 of file zfstream.cc.

133 {
134  bool testb = mode & std::ios_base::binary;
135  bool testi = mode & std::ios_base::in;
136  bool testo = mode & std::ios_base::out;
137  bool testt = mode & std::ios_base::trunc;
138  bool testa = mode & std::ios_base::app;
139 
140  // Check for valid flag combinations - see [27.8.1.3.2] (Table 92)
141  // Original zfstream hardcoded the compression level to maximum here...
142  // Double the time for less than 1% size improvement seems
143  // excessive though - keeping it at the default level
144  // To change back, just append "9" to the next three mode strings
145  if (!testi && testo && !testt && !testa)
146  strcpy(c_mode, "w");
147  if (!testi && testo && !testt && testa)
148  strcpy(c_mode, "a");
149  if (!testi && testo && testt && !testa)
150  strcpy(c_mode, "w");
151  if (testi && !testo && !testt && !testa)
152  strcpy(c_mode, "r");
153  // No read/write mode yet
154 // if (testi && testo && !testt && !testa)
155 // strcpy(c_mode, "r+");
156 // if (testi && testo && testt && !testa)
157 // strcpy(c_mode, "w+");
158 
159  // Mode string should be empty for invalid combination of flags
160  if (strlen(c_mode) == 0)
161  return false;
162  if (testb)
163  strcat(c_mode, "b");
164  return true;
165 }

References binary(), in, and out.

Referenced by attach(), and open().

◆ overflow() [1/2]

int gzfilebuf::overflow ( int  c = EOF)
protectedvirtual

Definition at line 173 of file zfstream.cpp.

173  {
174 
175  if ( !is_open() || !(mode & ios::out) )
176  return EOF;
177 
178  if ( !base() ) {
179  if ( allocate() == EOF )
180  return EOF;
181  setg(0,0,0);
182  } else {
183  if (in_avail()) {
184  return EOF;
185  }
186  if (out_waiting()) {
187  if (flushbuf() == EOF)
188  return EOF;
189  }
190  }
191 
192  int bl = blen();
193  setp( base(), base() + bl);
194 
195  if ( c != EOF ) {
196 
197  *pptr() = c;
198  pbump(1);
199 
200  }
201 
202  return 0;
203 
204 }
static RzILOpEffect * bl(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:1098
int flushbuf()
Definition: zfstream.cpp:218
#define c(i)
Definition: sha256.c:43
static void * allocate(bool compress, int compression_flags, zip_error_t *error)

References allocate(), bl(), c, flushbuf(), is_open(), and out.

◆ overflow() [2/2]

gzfilebuf::int_type gzfilebuf::overflow ( int_type  c = traits_type::eof())
protectedvirtual

Write put area to gzipped file.

Parameters
cExtra character to add to buffer contents.
Returns
Non-EOF on success, EOF on error.

This actually writes characters in stream buffer to gzipped file. With unbuffered output this is done one character at a time.

Definition at line 214 of file zfstream.cc.

215 {
216  // Determine whether put area is in use
217  if (this->pbase())
218  {
219  // Double-check pointer range
220  if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
221  return traits_type::eof();
222  // Add extra character to buffer if not EOF
223  if (!traits_type::eq_int_type(c, traits_type::eof()))
224  {
225  *(this->pptr()) = traits_type::to_char_type(c);
226  this->pbump(1);
227  }
228  // Number of characters to write to file
229  int bytes_to_write = this->pptr() - this->pbase();
230  // Overflow doesn't fail if nothing is to be written
231  if (bytes_to_write > 0)
232  {
233  // If the file hasn't been opened for writing, produce error
234  if (!this->is_open() || !(io_mode & std::ios_base::out))
235  return traits_type::eof();
236  // If gzipped file won't accept all bytes written to it, fail
237  if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write)
238  return traits_type::eof();
239  // Reset next pointer to point to pbase on success
240  this->pbump(-bytes_to_write);
241  }
242  }
243  // Write extra character to file if not EOF
244  else if (!traits_type::eq_int_type(c, traits_type::eof()))
245  {
246  // If the file hasn't been opened for writing, produce error
247  if (!this->is_open() || !(io_mode & std::ios_base::out))
248  return traits_type::eof();
249  // Impromptu char buffer (allows "unbuffered" output)
250  char_type last_char = traits_type::to_char_type(c);
251  // If gzipped file won't accept this character, fail
252  if (gzwrite(file, &last_char, 1) != 1)
253  return traits_type::eof();
254  }
255 
256  // If you got here, you have succeeded (even if c was EOF)
257  // The return value should therefore be non-EOF
258  if (traits_type::eq_int_type(c, traits_type::eof()))
259  return traits_type::not_eof(c);
260  else
261  return c;
262 }

References c, gzwrite(), io_mode, is_open(), and out.

◆ seekoff()

streampos gzfilebuf::seekoff ( streamoff  off,
ios::seek_dir  dir,
int  which 
)
virtual

Definition at line 129 of file zfstream.cpp.

129  {
130 
131  return streampos(EOF);
132 
133 }

◆ setbuf()

std::streambuf * gzfilebuf::setbuf ( char_type *  p,
std::streamsize  n 
)
protectedvirtual

Installs external stream buffer.

Parameters
pPointer to char buffer.
nSize of external buffer.
Returns
this on success, NULL on failure.

Call setbuf(0,0) to enable unbuffered output.

Definition at line 266 of file zfstream.cc.

268 {
269  // First make sure stuff is sync'ed, for safety
270  if (this->sync() == -1)
271  return NULL;
272  // If buffering is turned off on purpose via setbuf(0,0), still allocate one...
273  // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at
274  // least a buffer of size 1 (very inefficient though, therefore make it bigger?)
275  // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems)
276  if (!p || !n)
277  {
278  // Replace existing buffer (if any) with small internal buffer
279  this->disable_buffer();
280  buffer = NULL;
281  buffer_size = 0;
282  own_buffer = true;
283  this->enable_buffer();
284  }
285  else
286  {
287  // Replace existing buffer (if any) with external buffer
288  this->disable_buffer();
289  buffer = p;
290  buffer_size = n;
291  own_buffer = false;
292  this->enable_buffer();
293  }
294  return this;
295 }
void disable_buffer()
Destroy internal buffer.
Definition: zfstream.cc:347

References buffer_size, disable_buffer(), enable_buffer(), n, NULL, own_buffer, p, and sync().

◆ setcompression()

int gzfilebuf::setcompression ( int  comp_level,
int  comp_strategy = Z_DEFAULT_STRATEGY 
)

Set compression level and strategy on the fly.

Parameters
comp_levelCompression level (see zlib.h for allowed values)
comp_strategyCompression strategy (see zlib.h for allowed values)
Returns
Z_OK on success, Z_STREAM_ERROR otherwise.

Unfortunately, these parameters cannot be modified separately, as the previous zfstream version assumed. Since the strategy is seldom changed, it can default and setcompression(level) then becomes like the old setcompressionlevel(level).

Definition at line 43 of file zfstream.cc.

45 {
46  return gzsetparams(file, comp_level, comp_strategy);
47 }
int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
Definition: gzwrite.c:597

References gzsetparams().

◆ setcompressionlevel()

int gzfilebuf::setcompressionlevel ( int  comp_level)

Definition at line 116 of file zfstream.cpp.

116  {
117 
118  return gzsetparams(file, comp_level, -2);
119 
120 }

References gzsetparams().

◆ setcompressionstrategy()

int gzfilebuf::setcompressionstrategy ( int  comp_strategy)

Definition at line 122 of file zfstream.cpp.

122  {
123 
124  return gzsetparams(file, -2, comp_strategy);
125 
126 }

References gzsetparams().

◆ showmanyc()

std::streamsize gzfilebuf::showmanyc ( )
protectedvirtual

Number of characters available in stream buffer.

Returns
Number of characters.

This indicates number of characters in get area of stream buffer. These characters can be read without accessing the gzipped file.

Definition at line 169 of file zfstream.cc.

170 {
171  // Calls to underflow will fail if file not opened for reading
172  if (!this->is_open() || !(io_mode & std::ios_base::in))
173  return -1;
174  // Make sure get area is in use
175  if (this->gptr() && (this->gptr() < this->egptr()))
176  return std::streamsize(this->egptr() - this->gptr());
177  else
178  return 0;
179 }

References in, io_mode, and is_open().

◆ sync() [1/2]

int gzfilebuf::sync ( )
virtual

Definition at line 206 of file zfstream.cpp.

206  {
207 
208  if ( !is_open() )
209  return EOF;
210 
211  if ( out_waiting() )
212  return flushbuf();
213 
214  return 0;
215 
216 }

References flushbuf(), and is_open().

Referenced by close(), setbuf(), and ~gzfilebuf().

◆ sync() [2/2]

virtual int gzfilebuf::sync ( )
protectedvirtual

Flush stream buffer to file.

Returns
0 on success, -1 on error.

This calls underflow(EOF) to do the job.

◆ underflow() [1/2]

gzfilebuf::int_type gzfilebuf::underflow ( )
protectedvirtual

Definition at line 135 of file zfstream.cpp.

135  {
136 
137  // If the file hasn't been opened for reading, error.
138  if ( !is_open() || !(mode & ios::in) )
139  return EOF;
140 
141  // if a buffer doesn't exists, allocate one.
142  if ( !base() ) {
143 
144  if ( (allocate()) == EOF )
145  return EOF;
146  setp(0,0);
147 
148  } else {
149 
150  if ( in_avail() )
151  return (unsigned char) *gptr();
152 
153  if ( out_waiting() ) {
154  if ( flushbuf() == EOF )
155  return EOF;
156  }
157 
158  }
159 
160  // Attempt to fill the buffer.
161 
162  int result = fillbuf();
163  if ( result == EOF ) {
164  // disable get area
165  setg(0,0,0);
166  return EOF;
167  }
168 
169  return (unsigned char) *gptr();
170 
171 }
int fillbuf()
Definition: zfstream.cpp:235

References allocate(), fillbuf(), flushbuf(), in, and is_open().

◆ underflow() [2/2]

virtual int_type gzfilebuf::underflow ( )
protectedvirtual

Fill get area from gzipped file.

Returns
First character in get area on success, EOF on error.

This actually reads characters from gzipped file to stream buffer. Always buffered.

Member Data Documentation

◆ buffer

char_type* gzfilebuf::buffer
private

Stream buffer.

For simplicity this remains allocated on the free store for the entire life span of the gzfilebuf object, unless replaced by setbuf.

Definition at line 207 of file zfstream.h.

Referenced by disable_buffer().

◆ buffer_size

std::streamsize gzfilebuf::buffer_size
private

Stream buffer size.

Defaults to system default buffer size (typically 8192 bytes). Modified by setbuf.

Definition at line 215 of file zfstream.h.

Referenced by disable_buffer(), enable_buffer(), and setbuf().

◆ file

gzFile gzfilebuf::file
private

Underlying file pointer.

Definition at line 35 of file zfstream.h.

◆ io_mode

std::ios_base::openmode gzfilebuf::io_mode
private

Mode in which file was opened.

Definition at line 191 of file zfstream.h.

Referenced by attach(), open(), overflow(), and showmanyc().

◆ mode

short gzfilebuf::mode
private

Definition at line 36 of file zfstream.h.

Referenced by attach(), open(), and test_group_name.GroupTest::run().

◆ own_buffer

bool gzfilebuf::own_buffer
private

True if this object owns stream buffer.

This makes the class responsible for deleting the buffer upon destruction.

Definition at line 223 of file zfstream.h.

Referenced by disable_buffer(), enable_buffer(), and setbuf().

◆ own_fd

bool gzfilebuf::own_fd
private

True if this object owns file descriptor.

This makes the class responsible for closing the file upon destruction.

Definition at line 199 of file zfstream.h.

Referenced by attach(), and open().

◆ own_file_descriptor

short gzfilebuf::own_file_descriptor
private

Definition at line 37 of file zfstream.h.

Referenced by attach(), open(), and ~gzfilebuf().


The documentation for this class was generated from the following files: