36 #if defined (HAVE_CONFIG_H)
46 #if defined (HAVE_ZLIB)
54 #define STASHED_CHARACTERS 16
55 #define BIGBUFSIZE (256 * 1024 + STASHED_CHARACTERS)
56 #define SMALLBUFSIZE 1
60 : m_file(nullptr), m_io_mode(std::ios_base::openmode(0)), m_own_fd(false),
61 m_buffer(nullptr), m_buffer_size(
BIGBUFSIZE), m_own_buffer(true)
83 return gzsetparams (
m_file, comp_level, comp_strategy);
94 if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
98 char char_mode[6] =
"\0\0\0\0\0";
103 if ((
m_file = gzopen (name, char_mode)) ==
nullptr)
121 if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
125 char char_mode[6] =
"\0\0\0\0\0";
130 if ((
m_file = gzdopen (fd, char_mode)) ==
nullptr)
150 if (this->
sync () == -1)
170 bool testi = mode & std::ios_base::in;
171 bool testo = mode & std::ios_base::out;
173 bool testa = mode & std::ios_base::app;
180 if (! testi && testo && ! testt && ! testa)
181 strcpy (c_mode,
"w");
182 if (! testi && testo && ! testt && testa)
183 strcpy (c_mode,
"a");
184 if (! testi && testo && testt && ! testa)
185 strcpy (c_mode,
"w");
186 if (testi && ! testo && ! testt && ! testa)
187 strcpy (c_mode,
"r");
198 strcat (c_mode,
"b");
211 if (this->gptr () && (this->gptr () < this->egptr ()))
212 return std::streamsize (this->egptr () - this->gptr ());
226 if (gzseek (
m_file, this->gptr () - this->egptr () - 1,
SEEK_CUR) < 0)
227 return traits_type::eof ();
240 return traits_type::eof ();
248 gzfilebuf::int_type ret = traits_type::to_int_type (*(this->gptr ()));
250 return traits_type::eof ();
255 return traits_type::eof ();
265 if (this->gptr () && (this->gptr () < this->egptr ()))
266 return traits_type::to_int_type (*(this->gptr ()));
270 return traits_type::eof ();
278 if (ptr2 > this->eback ())
292 return traits_type::eof ();
298 return traits_type::to_int_type (*(this->gptr ()));
309 if (this->pptr () > this->epptr () || this->pptr () < this->pbase ())
310 return traits_type::eof ();
312 if (! traits_type::eq_int_type (c, traits_type::eof ()))
314 *(this->pptr ()) = traits_type::to_char_type (c);
318 int bytes_to_write = this->pptr () - this->pbase ();
320 if (bytes_to_write > 0)
324 return traits_type::eof ();
326 if (gzwrite (
m_file, this->pbase (), bytes_to_write)
328 return traits_type::eof ();
330 this->pbump (-bytes_to_write);
334 else if (! traits_type::eq_int_type (c, traits_type::eof ()))
338 return traits_type::eof ();
340 char_type last_char = traits_type::to_char_type (c);
342 if (gzwrite (
m_file, &last_char, 1) != 1)
343 return traits_type::eof ();
348 if (traits_type::eq_int_type (c, traits_type::eof ()))
349 return traits_type::not_eof (c);
359 if (this->
sync () == -1)
391 return traits_type::eq_int_type (this->
overflow (),
392 traits_type::eof ()) ? -1 : 0;
425 this->setp (
nullptr,
nullptr);
445 if (! this->pbase ())
449 this->setg (
nullptr,
nullptr,
nullptr);
450 this->setp (
nullptr,
nullptr);
459 this->setp (
nullptr,
nullptr);
468 std::ios_base::openmode)
470 pos_type ret = pos_type (off_type (-1));
474 off_type computed_off = off;
476 if ((
m_io_mode & std::ios_base::in) && way == std::ios_base::cur)
477 computed_off += this->gptr () - this->egptr ();
481 if (off == 0 && way == std::ios_base::cur)
482 return pos_type (gztell (
m_file) + computed_off);
484 if (way == std::ios_base::beg)
486 else if (way == std::ios_base::cur)
506 pos_type ret = pos_type (off_type (-1));
525 : std::
istream (nullptr), m_sb ()
526 { this->init (&
m_sb); }
530 : std::
istream (nullptr), m_sb ()
533 this->
open (name, mode);
538 : std::
istream (nullptr), m_sb ()
548 if (!
m_sb.
open (name, mode | std::ios_base::in))
549 this->setstate (std::ios_base::failbit);
558 if (!
m_sb.
attach (fd, mode | std::ios_base::in))
559 this->setstate (std::ios_base::failbit);
569 this->setstate (std::ios_base::failbit);
574 : std::
ostream (nullptr), m_sb ()
575 { this->init (&
m_sb); }
579 : std::
ostream (nullptr), m_sb ()
582 this->
open (name, mode);
587 : std::
ostream (nullptr), m_sb ()
597 if (!
m_sb.
open (name, mode | std::ios_base::out))
598 this->setstate (std::ios_base::failbit);
607 if (!
m_sb.
attach (fd, mode | std::ios_base::out))
608 this->setstate (std::ios_base::failbit);
618 this->setstate (std::ios_base::failbit);
Gzipped file stream buffer class.
gzfilebuf * close()
Close gzipped file.
bool m_own_fd
True if this object owns file descriptor.
bool is_open() const
Check if file is open.
virtual int_type underflow()
Fill get area from gzipped file.
virtual int_type overflow(int_type c=traits_type::eof())
Write put area to gzipped file.
char_type * m_buffer
Stream buffer.
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.
std::ios_base::openmode m_io_mode
Mode in which file was opened.
virtual int_type pbackfail(int_type c=traits_type::eof())
virtual std::streambuf * setbuf(char_type *p, std::streamsize n)
Installs external stream buffer.
bool m_own_buffer
True if this object owns stream buffer.
void disable_buffer()
Destroy internal buffer.
gzfilebuf * open(const char *name, std::ios_base::openmode mode)
Open gzipped file.
virtual pos_type seekpos(pos_type sp, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Alters the stream positions.
bool open_mode(std::ios_base::openmode mode, char *c_mode) const
Convert ios open mode int to mode string used by zlib.
int setcompression(int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY)
Set compression level and strategy on the fly.
void enable_buffer()
Allocate internal buffer.
virtual int sync()
Flush stream buffer to file.
gzfilebuf * attach(int fd, std::ios_base::openmode mode)
Attach to already open gzipped file.
gzFile m_file
Underlying file pointer.
virtual std::streamsize showmanyc()
Number of characters available in stream buffer.
std::streamsize m_buffer_size
Stream buffer size.
void close()
Close gzipped file.
void attach(int fd, std::ios_base::openmode mode=std::ios_base::in)
Attach to already open gzipped file.
gzfilebuf m_sb
Underlying stream buffer.
void open(const char *name, std::ios_base::openmode mode=std::ios_base::in)
Open gzipped file.
void close()
Close gzipped file.
gzfilebuf m_sb
Underlying stream buffer.
void attach(int fd, std::ios_base::openmode mode=std::ios_base::out)
Attach to already open gzipped file.
void open(const char *name, std::ios_base::openmode mode=std::ios_base::out)
Open gzipped file.
#define STASHED_CHARACTERS
std::complex< T > trunc(const std::complex< T > &x)
T::size_type strlen(const typename T::value_type *str)