33 #if defined (HAVE_CONFIG_H) 41 #if defined (HAVE_ZLIB) 49 #define STASHED_CHARACTERS 16 50 #define BIGBUFSIZE (256 * 1024 + STASHED_CHARACTERS) 51 #define SMALLBUFSIZE 1 55 :
file(nullptr), io_mode(
std::ios_base::openmode(0)), own_fd(
false),
56 buffer(nullptr), buffer_size(
BIGBUFSIZE), own_buffer(true)
78 return gzsetparams (
file, comp_level, comp_strategy);
89 if ((mode & std::ios_base::in) && (
mode & std::ios_base::out))
93 char char_mode[6] =
"\0\0\0\0\0";
98 if ((
file = gzopen (
name, char_mode)) ==
nullptr)
116 if ((mode & std::ios_base::in) && (
mode & std::ios_base::out))
120 char char_mode[6] =
"\0\0\0\0\0";
125 if ((
file = gzdopen (fd, char_mode)) ==
nullptr)
145 if (this->
sync () == -1)
147 if (gzclose (
file) < 0)
165 bool testi =
mode & std::ios_base::in;
166 bool testo =
mode & std::ios_base::out;
168 bool testa =
mode & std::ios_base::app;
175 if (! testi && testo && ! testt && ! testa)
176 strcpy (c_mode,
"w");
177 if (! testi && testo && ! testt && testa)
178 strcpy (c_mode,
"a");
179 if (! testi && testo && testt && ! testa)
180 strcpy (c_mode,
"w");
181 if (testi && ! testo && ! testt && ! testa)
182 strcpy (c_mode,
"r");
193 strcat (c_mode,
"b");
206 if (this->gptr () && (this->gptr () < this->egptr ()))
207 return std::streamsize (this->egptr () - this->gptr ());
221 if (gzseek (
file, this->gptr () - this->egptr () - 1,
SEEK_CUR) < 0)
222 return traits_type::eof ();
235 return traits_type::eof ();
243 gzfilebuf::int_type ret = traits_type::to_int_type (*(this->gptr ()));
245 return traits_type::eof ();
250 return traits_type::eof ();
260 if (this->gptr () && (this->gptr () < this->egptr ()))
261 return traits_type::to_int_type (*(this->gptr ()));
265 return traits_type::eof ();
273 if (ptr2 > this->eback ())
287 return traits_type::eof ();
293 return traits_type::to_int_type (*(this->gptr ()));
304 if (this->pptr () > this->epptr () || this->pptr () < this->pbase ())
305 return traits_type::eof ();
307 if (! traits_type::eq_int_type (
c, traits_type::eof ()))
309 *(this->pptr ()) = traits_type::to_char_type (
c);
313 int bytes_to_write = this->pptr () - this->pbase ();
315 if (bytes_to_write > 0)
319 return traits_type::eof ();
321 if (gzwrite (
file, this->pbase (), bytes_to_write) != bytes_to_write)
322 return traits_type::eof ();
324 this->pbump (-bytes_to_write);
328 else if (! traits_type::eq_int_type (
c, traits_type::eof ()))
332 return traits_type::eof ();
334 char_type last_char = traits_type::to_char_type (
c);
336 if (gzwrite (
file, &last_char, 1) != 1)
337 return traits_type::eof ();
342 if (traits_type::eq_int_type (
c, traits_type::eof ()))
343 return traits_type::not_eof (
c);
353 if (this->
sync () == -1)
385 return traits_type::eq_int_type (this->
overflow (),
386 traits_type::eof ()) ? -1 : 0;
419 this->setp (
nullptr,
nullptr);
439 if (! this->pbase ())
443 this->setg (
nullptr,
nullptr,
nullptr);
444 this->setp (
nullptr,
nullptr);
453 this->setp (
nullptr,
nullptr);
462 std::ios_base::openmode)
464 pos_type ret = pos_type (off_type (-1));
468 off_type computed_off = off;
470 if ((
io_mode & std::ios_base::in) && way == std::ios_base::cur)
471 computed_off += this->gptr () - this->egptr ();
475 if (off == 0 && way == std::ios_base::cur)
476 return pos_type (gztell (
file) + computed_off);
478 if (way == std::ios_base::beg)
480 else if (way == std::ios_base::cur)
486 if (
io_mode & std::ios_base::in)
500 pos_type ret = pos_type (off_type (-1));
506 if (
io_mode & std::ios_base::in)
519 :
std::istream (nullptr), sb ()
524 :
std::istream (nullptr), sb ()
532 :
std::istream (nullptr), sb ()
543 this->setstate (std::ios_base::failbit);
553 this->setstate (std::ios_base::failbit);
563 this->setstate (std::ios_base::failbit);
568 :
std::ostream (nullptr), sb ()
573 :
std::ostream (nullptr), sb ()
581 :
std::ostream (nullptr), sb ()
592 this->setstate (std::ios_base::failbit);
602 this->setstate (std::ios_base::failbit);
612 this->setstate (std::ios_base::failbit);
gzfilebuf * open(const char *name, std::ios_base::openmode mode)
Open gzipped file.
For example cd octave end example noindent changes the current working directory to file
void attach(int fd, std::ios_base::openmode mode=std::ios_base::out)
Attach to already open 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.
gzfilebuf sb
Underlying stream buffer.
void open(const char *name, std::ios_base::openmode mode=std::ios_base::in)
Open gzipped file.
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
virtual std::streambuf * setbuf(char_type *p, std::streamsize n)
Installs external stream buffer.
#define STASHED_CHARACTERS
void enable_buffer()
Allocate internal buffer.
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
virtual int_type overflow(int_type c=traits_type::eof())
Write put area to gzipped file.
int setcompression(int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY)
Set compression level and strategy on the fly.
gzfilebuf * close()
Close gzipped file.
std::ios_base::openmode io_mode
Mode in which file was opened.
gzFile file
Underlying file pointer.
bool is_open() const
Check if file is open.
nd deftypefn *std::string name
virtual int_type pbackfail(int_type c=traits_type::eof())
Gzipped file stream buffer class.
void open(const char *name, std::ios_base::openmode mode=std::ios_base::out)
Open gzipped file.
bool own_buffer
True if this object owns stream buffer.
std::complex< T > trunc(const std::complex< T > &x)
void attach(int fd, std::ios_base::openmode mode=std::ios_base::in)
Attach to already open gzipped file.
void close()
Close 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.
T::size_type strlen(const typename T::value_type *str)
gzfilebuf sb
Underlying stream buffer.
void disable_buffer()
Destroy internal buffer.
std::streamsize buffer_size
Stream buffer size.
gzfilebuf * attach(int fd, std::ios_base::openmode mode)
Attach to already open gzipped file.
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.
virtual int sync()
Flush stream buffer to file.
bool own_fd
True if this object owns file descriptor.
void close()
Close gzipped file.
virtual int_type underflow()
Fill get area from gzipped file.