15 #define BIGBUFSIZE BUFSIZ 16 #define SMALLBUFSIZE 1 22 : file(
NULL), io_mode(
std::ios_base::openmode(0)), own_fd(
false),
26 this->disable_buffer();
38 this->disable_buffer();
46 return gzsetparams(file, comp_level, comp_strategy);
52 std::ios_base::openmode
mode)
62 char char_mode[6] =
"\0\0\0\0\0";
71 this->enable_buffer();
80 std::ios_base::openmode
mode)
90 char char_mode[6] =
"\0\0\0\0\0";
99 this->enable_buffer();
115 if (this->
sync() == -1)
123 this->disable_buffer();
138 bool testa = mode & std::ios_base::app;
145 if (!testi && testo && !testt && !testa)
147 if (!testi && testo && !testt && testa)
149 if (!testi && testo && testt && !testa)
151 if (testi && !testo && !testt && !testa)
160 if (strlen(c_mode) == 0)
175 if (this->gptr() && (this->gptr() < this->egptr()))
176 return std::streamsize(this->egptr() - this->gptr());
188 if (this->gptr() && (this->gptr() < this->egptr()))
189 return traits_type::to_int_type(*(this->gptr()));
193 return traits_type::eof();
203 return traits_type::eof();
209 return traits_type::to_int_type(*(this->gptr()));
220 if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
221 return traits_type::eof();
223 if (!traits_type::eq_int_type(c, traits_type::eof()))
225 *(this->pptr()) = traits_type::to_char_type(c);
229 int bytes_to_write = this->pptr() - this->pbase();
231 if (bytes_to_write > 0)
235 return traits_type::eof();
237 if (
gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write)
238 return traits_type::eof();
240 this->pbump(-bytes_to_write);
244 else if (!traits_type::eq_int_type(c, traits_type::eof()))
248 return traits_type::eof();
250 char_type last_char = traits_type::to_char_type(c);
252 if (
gzwrite(file, &last_char, 1) != 1)
253 return traits_type::eof();
258 if (traits_type::eq_int_type(c, traits_type::eof()))
259 return traits_type::not_eof(c);
270 if (this->
sync() == -1)
279 this->disable_buffer();
283 this->enable_buffer();
288 this->disable_buffer();
292 this->enable_buffer();
301 return traits_type::eq_int_type(this->
overflow(), traits_type::eof()) ? -1 : 0;
308 gzfilebuf::enable_buffer()
311 if (own_buffer && !
buffer)
317 buffer =
new char_type[buffer_size];
330 buffer =
new char_type[buffer_size];
347 gzfilebuf::disable_buffer()
375 : std::istream(
NULL), sb()
380 std::ios_base::openmode
mode)
384 this->
open(name, mode);
389 std::ios_base::openmode
mode)
399 std::ios_base::openmode
mode)
402 this->setstate(std::ios_base::failbit);
410 std::ios_base::openmode
mode)
413 this->setstate(std::ios_base::failbit);
423 this->setstate(std::ios_base::failbit);
430 : std::ostream(
NULL), sb()
435 std::ios_base::openmode
mode)
439 this->
open(name, mode);
444 std::ios_base::openmode
mode)
454 std::ios_base::openmode
mode)
457 this->setstate(std::ios_base::failbit);
465 std::ios_base::openmode
mode)
468 this->setstate(std::ios_base::failbit);
478 this->setstate(std::ios_base::failbit);
void attach(int fd, std::ios_base::openmode mode=std::ios_base::out)
Attach to already open gzipped file.
gzfilebuf * attach(int file_descriptor, int io_mode)
void open(const char *name, std::ios_base::openmode mode=std::ios_base::in)
Open gzipped file.
int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
int ZEXPORT gzclose(gzFile file)
virtual std::streambuf * setbuf(char_type *p, std::streamsize n)
Installs external stream buffer.
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
gzfilebuf * open(const char *name, int io_mode)
int setcompression(int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY)
Set compression level and strategy on the fly.
const GLuint GLenum const GLvoid * binary
local int out(void *out_desc, unsigned char *buf, unsigned len)
Gzipped file stream buffer class.
void open(const char *name, std::ios_base::openmode mode=std::ios_base::out)
Open gzipped file.
gzFile ZEXPORT gzdopen(int fd, const char *mode)
void attach(int fd, std::ios_base::openmode mode=std::ios_base::in)
Attach to already open gzipped file.
void close()
Close gzipped file.
GLuint const GLchar * name
bool open_mode(std::ios_base::openmode mode, char *c_mode) const
Convert ios open mode int to mode string used by zlib.
virtual std::streamsize showmanyc()
Number of characters available in stream buffer.
png_infop png_bytep png_size_t buffer_size
gzFile ZEXPORT gzopen(char *path, const char *mode) const
virtual int overflow(int=EOF)
void close()
Close gzipped file.
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)