Gzipped file stream buffer class. More...
#include "gzfstream.h"
Public Member Functions | |
gzfilebuf () | |
virtual | ~gzfilebuf () |
gzfilebuf * | attach (int fd, std::ios_base::openmode mode) |
Attach to already open gzipped file. More... | |
gzfilebuf * | close () |
Close gzipped file. More... | |
bool | is_open () const |
Check if file is open. More... | |
gzfilebuf * | open (const char *name, std::ios_base::openmode mode) |
Open gzipped file. More... | |
int | setcompression (int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY) |
Set compression level and strategy on the fly. More... | |
Protected Member Functions | |
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 int_type | overflow (int_type c=traits_type::eof()) |
Write put area to gzipped file. More... | |
virtual int_type | pbackfail (int_type c=traits_type::eof()) |
virtual pos_type | seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) |
Alters the stream positions. More... | |
virtual pos_type | seekpos (pos_type sp, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) |
Alters the stream positions. More... | |
virtual std::streambuf * | setbuf (char_type *p, std::streamsize n) |
Installs external stream buffer. More... | |
virtual std::streamsize | showmanyc () |
Number of characters available in stream buffer. More... | |
virtual int | sync () |
Flush stream buffer to file. More... | |
virtual int_type | underflow () |
Fill get area from gzipped file. More... | |
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 55 of file gzfstream.h.
gzfilebuf::gzfilebuf | ( | ) |
Definition at line 59 of file gzfstream.cc.
|
virtual |
Definition at line 68 of file gzfstream.cc.
gzfilebuf * gzfilebuf::attach | ( | int | fd, |
std::ios_base::openmode | mode | ||
) |
Attach to already open gzipped file.
fd | File descriptor. |
mode | Open mode flags. |
this
on success, NULL on failure. Definition at line 115 of file gzfstream.cc.
References is_open(), and open_mode().
Referenced by gzifstream::attach(), and gzofstream::attach().
gzfilebuf * gzfilebuf::close | ( | ) |
Close gzipped file.
this
on success, NULL on failure. Definition at line 142 of file gzfstream.cc.
References is_open(), and sync().
Referenced by ~gzfilebuf(), gzifstream::close(), and gzofstream::close().
|
inline |
Check if file is open.
Definition at line 86 of file gzfstream.h.
Referenced by attach(), close(), gzifstream::is_open(), gzofstream::is_open(), open(), overflow(), pbackfail(), seekoff(), seekpos(), showmanyc(), and underflow().
gzfilebuf * gzfilebuf::open | ( | const char * | name, |
std::ios_base::openmode | mode | ||
) |
Open gzipped file.
name | Filename. |
mode | Open mode flags. |
this
on success, NULL on failure. Definition at line 88 of file gzfstream.cc.
References is_open(), and open_mode().
Referenced by gzifstream::open(), and gzofstream::open().
|
protected |
|
protectedvirtual |
Write put area to gzipped file.
c | Extra character to add to buffer contents. |
This actually writes characters in stream buffer to gzipped file. With unbuffered output this is done one character at a time.
Definition at line 303 of file gzfstream.cc.
References is_open().
|
protectedvirtual |
Definition at line 222 of file gzfstream.cc.
|
protectedvirtual |
Alters the stream positions.
Each derived class provides its own appropriate behavior.
Definition at line 467 of file gzfstream.cc.
References is_open(), overflow(), SEEK_CUR, SEEK_END, and SEEK_SET.
|
protectedvirtual |
Alters the stream positions.
Each derived class provides its own appropriate behavior.
Definition at line 504 of file gzfstream.cc.
References is_open(), overflow(), and SEEK_SET.
|
protectedvirtual |
Installs external stream buffer.
p | Pointer to char buffer. |
n | Size of external buffer. |
this
on success, NULL on failure.Call setbuf(0,0) to enable unbuffered output.
Definition at line 356 of file gzfstream.cc.
int gzfilebuf::setcompression | ( | int | comp_level, |
int | comp_strategy = Z_DEFAULT_STRATEGY |
||
) |
Set compression level and strategy on the fly.
comp_level | Compression level (see zlib.h for allowed values) |
comp_strategy | Compression strategy (see zlib.h for allowed values) |
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 81 of file gzfstream.cc.
|
protectedvirtual |
Number of characters available in stream buffer.
This indicates number of characters in get area of stream buffer. These characters can be read without accessing the gzipped file.
Definition at line 205 of file gzfstream.cc.
References is_open().
|
protectedvirtual |
Flush stream buffer to file.
This calls underflow(EOF) to do the job.
Definition at line 389 of file gzfstream.cc.
References overflow().
Referenced by ~gzfilebuf(), close(), and setbuf().
|
protectedvirtual |
Fill get area from gzipped file.
This actually reads characters from gzipped file to stream buffer. Always buffered.
Definition at line 260 of file gzfstream.cc.
References is_open(), and STASHED_CHARACTERS.