48 #define STASHED_CHARACTERS 16
49 #define BIGBUFSIZE (256 * 1024 + STASHED_CHARACTERS)
50 #define SMALLBUFSIZE 1
56 : file(0), io_mode(
std::ios_base::openmode(0)), own_fd(false),
57 buffer(0), buffer_size(
BIGBUFSIZE), own_buffer(true)
79 return gzsetparams (
file, comp_level, comp_strategy);
90 if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
94 char char_mode[6] =
"\0\0\0\0\0";
99 if ((
file = gzopen (name, char_mode)) == 0)
117 if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
121 char char_mode[6] =
"\0\0\0\0\0";
126 if ((
file = gzdopen (fd, char_mode)) == 0)
146 if (this->
sync () == -1)
148 if (gzclose (
file) < 0)
166 bool testi = mode & std::ios_base::in;
167 bool testo = mode & std::ios_base::out;
168 bool testt = mode & std::ios_base::trunc;
169 bool testa = mode & std::ios_base::app;
176 if (!testi && testo && !testt && !testa)
177 strcpy (c_mode,
"w");
178 if (!testi && testo && !testt && testa)
179 strcpy (c_mode,
"a");
180 if (!testi && testo && testt && !testa)
181 strcpy (c_mode,
"w");
182 if (testi && !testo && !testt && !testa)
183 strcpy (c_mode,
"r");
191 if (strlen (c_mode) == 0)
194 strcat (c_mode,
"b");
207 if (this->gptr () && (this->gptr () < this->egptr ()))
208 return std::streamsize (this->egptr () - this->gptr ());
222 if (gzseek (
file, this->gptr () - this->egptr () - 1,
SEEK_CUR) < 0)
223 return traits_type::eof ();
236 return traits_type::eof ();
244 gzfilebuf::int_type ret = traits_type::to_int_type (*(this->gptr ()));
246 return traits_type::eof ();
251 return traits_type::eof ();
261 if (this->gptr () && (this->gptr () < this->egptr ()))
262 return traits_type::to_int_type (*(this->gptr ()));
266 return traits_type::eof ();
274 if (ptr2 > this->eback ())
288 return traits_type::eof ();
294 return traits_type::to_int_type (*(this->gptr ()));
305 if (this->pptr () > this->epptr () || this->pptr () < this->pbase ())
306 return traits_type::eof ();
308 if (! traits_type::eq_int_type (c, traits_type::eof ()))
310 *(this->pptr ()) = traits_type::to_char_type (c);
314 int bytes_to_write = this->pptr () - this->pbase ();
316 if (bytes_to_write > 0)
320 return traits_type::eof ();
322 if (gzwrite (
file, this->pbase (), bytes_to_write) != bytes_to_write)
323 return traits_type::eof ();
325 this->pbump (-bytes_to_write);
329 else if (! traits_type::eq_int_type (c, traits_type::eof ()))
333 return traits_type::eof ();
335 char_type last_char = traits_type::to_char_type (c);
337 if (gzwrite (
file, &last_char, 1) != 1)
338 return traits_type::eof ();
343 if (traits_type::eq_int_type (c, traits_type::eof ()))
344 return traits_type::not_eof (c);
354 if (this->
sync () == -1)
386 return traits_type::eq_int_type (this->
overflow (),
387 traits_type::eof ()) ? -1 : 0;
440 if (! this->pbase ())
444 this->setg (0, 0, 0);
463 std::ios_base::openmode)
465 pos_type ret = pos_type (off_type (-1));
469 off_type computed_off = off;
471 if ((
io_mode & std::ios_base::in) && way == std::ios_base::cur)
472 computed_off += this->gptr () - this->egptr ();
476 if (off == 0 && way == std::ios_base::cur)
477 return pos_type (gztell (
file) + computed_off);
479 if (way == std::ios_base::beg)
481 else if (way == std::ios_base::cur)
487 if (
io_mode & std::ios_base::in)
501 pos_type ret = pos_type (off_type (-1));
507 if (
io_mode & std::ios_base::in)
522 :
std::istream (0), sb ()
523 { this->init (&
sb); }
527 :
std::istream (0), sb ()
530 this->
open (name, mode);
535 :
std::istream (0), sb ()
545 if (!
sb.
open (name, mode | std::ios_base::in))
546 this->setstate (std::ios_base::failbit);
555 if (!
sb.
attach (fd, mode | std::ios_base::in))
556 this->setstate (std::ios_base::failbit);
566 this->setstate (std::ios_base::failbit);
573 :
std::ostream (0), sb ()
574 { this->init (&
sb); }
578 :
std::ostream (0), sb ()
581 this->
open (name, mode);
586 :
std::ostream (0), 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);
gzfilebuf * open(const char *name, std::ios_base::openmode mode)
Open gzipped file.
static void clear(octave_shlib &oct_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.
virtual std::streambuf * setbuf(char_type *p, std::streamsize n)
Installs external stream buffer.
#define STASHED_CHARACTERS
void enable_buffer()
Allocate internal buffer.
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.
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.
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.
bool open_mode(std::ios_base::openmode mode, char *c_mode) const
Convert ios open mode int to mode string used by zlib.
virtual pos_type seekpos(pos_type sp, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Alters the stream positions.
gzfilebuf sb
Underlying stream buffer.
bool is_open() const
Check if file is open.
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.
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.