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 : file(nullptr), io_mode(std::ios_base::openmode(0)), own_fd(false),
61 buffer(nullptr), buffer_size(
BIGBUFSIZE), own_buffer(true)
83 return gzsetparams (
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 ((
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 ((
file = gzdopen (fd, char_mode)) ==
nullptr)
150 if (this->
sync () == -1)
152 if (gzclose (
file) < 0)
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 (
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 (
file, this->pbase (), bytes_to_write) != bytes_to_write)
327 return traits_type::eof ();
329 this->pbump (-bytes_to_write);
333 else if (! traits_type::eq_int_type (c, traits_type::eof ()))
337 return traits_type::eof ();
339 char_type last_char = traits_type::to_char_type (c);
341 if (gzwrite (
file, &last_char, 1) != 1)
342 return traits_type::eof ();
347 if (traits_type::eq_int_type (c, traits_type::eof ()))
348 return traits_type::not_eof (c);
358 if (this->
sync () == -1)
390 return traits_type::eq_int_type (this->
overflow (),
391 traits_type::eof ()) ? -1 : 0;
424 this->setp (
nullptr,
nullptr);
444 if (! this->pbase ())
448 this->setg (
nullptr,
nullptr,
nullptr);
449 this->setp (
nullptr,
nullptr);
458 this->setp (
nullptr,
nullptr);
467 std::ios_base::openmode)
469 pos_type ret = pos_type (off_type (-1));
473 off_type computed_off = off;
475 if ((
io_mode & std::ios_base::in) && way == std::ios_base::cur)
476 computed_off += this->gptr () - this->egptr ();
480 if (off == 0 && way == std::ios_base::cur)
481 return pos_type (gztell (
file) + computed_off);
483 if (way == std::ios_base::beg)
485 else if (way == std::ios_base::cur)
491 if (
io_mode & std::ios_base::in)
505 pos_type ret = pos_type (off_type (-1));
511 if (
io_mode & std::ios_base::in)
524 : std::istream (nullptr), sb ()
525 { this->init (&
sb); }
529 : std::istream (nullptr), sb ()
532 this->
open (name, mode);
537 : std::istream (nullptr), sb ()
547 if (!
sb.
open (
name, mode | std::ios_base::in))
548 this->setstate (std::ios_base::failbit);
557 if (!
sb.
attach (fd, mode | std::ios_base::in))
558 this->setstate (std::ios_base::failbit);
568 this->setstate (std::ios_base::failbit);
573 : std::ostream (nullptr), sb ()
574 { this->init (&
sb); }
578 : std::ostream (nullptr), sb ()
581 this->
open (name, mode);
586 : std::ostream (nullptr), sb ()
596 if (!
sb.
open (
name, mode | std::ios_base::out))
597 this->setstate (std::ios_base::failbit);
606 if (!
sb.
attach (fd, mode | std::ios_base::out))
607 this->setstate (std::ios_base::failbit);
617 this->setstate (std::ios_base::failbit);
Gzipped file stream buffer class.
std::streamsize buffer_size
Stream buffer size.
gzfilebuf * close()
Close gzipped file.
gzFile file
Underlying file pointer.
bool is_open() const
Check if file is open.
virtual int_type underflow()
Fill get area from gzipped file.
std::ios_base::openmode io_mode
Mode in which file was opened.
bool own_fd
True if this object owns file descriptor.
virtual int_type overflow(int_type c=traits_type::eof())
Write put area to gzipped file.
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.
virtual int_type pbackfail(int_type c=traits_type::eof())
virtual std::streambuf * setbuf(char_type *p, std::streamsize n)
Installs external stream buffer.
void disable_buffer()
Destroy internal buffer.
gzfilebuf * open(const char *name, std::ios_base::openmode mode)
Open gzipped file.
char_type * buffer
Stream buffer.
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.
bool own_buffer
True if this object owns stream buffer.
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.
virtual std::streamsize showmanyc()
Number of characters available in stream buffer.
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 sb
Underlying stream buffer.
void open(const char *name, std::ios_base::openmode mode=std::ios_base::in)
Open gzipped file.
gzfilebuf sb
Underlying stream buffer.
void close()
Close gzipped file.
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.
std::complex< T > trunc(const std::complex< T > &x)
T::size_type strlen(const typename T::value_type *str)
octave_value::octave_value(const Array< char > &chm, char type) return retval
#define STASHED_CHARACTERS