30 #include <sys/types.h>
37 namespace gzstream_detail
80 if ( mode_r == std::ios_base::in )
82 _fd =
::open( name_r, O_RDONLY | O_CLOEXEC );
85 else if ( mode_r == std::ios_base::out )
87 _fd =
::open( name_r, O_WRONLY|O_CREAT|O_CLOEXEC, 0666 );
104 setg( NULL, NULL, NULL );
129 int r = gzclose(
_file );
141 _mode = std::ios_base::openmode(0);
143 setg( NULL, NULL, NULL );
159 if ( pbase() < pptr() ) {
161 if ( traits_type::eq_int_type( res, traits_type::eof() ) )
172 fgzstreambuf::int_type
175 int_type ret = traits_type::eof();
178 if ( ! traits_type::eq_int_type( c, traits_type::eof() ) )
180 *pptr() = traits_type::to_char_type( c );
183 if ( pbase() <= pptr() )
185 if (
zWriteFrom( pbase(), pptr() - pbase() ) )
188 ret = traits_type::not_eof( c );
201 fgzstreambuf::int_type
204 int_type ret = traits_type::eof();
207 if ( gptr() < egptr() )
208 return traits_type::to_int_type( *gptr() );
214 ret = traits_type::to_int_type( *gptr() );
234 int read = gzread(
_file, buffer_r, maxcount_r );
251 if ( (written = gzwrite(
_file, buffer_r, count_r )) == 0 )
254 return( written == count_r );
262 fgzstreambuf::pos_type
265 z_off_t ret = gzseek(
_file, off_r, way_r );
276 fgzstreambuf::pos_type
279 z_off_t ret = gztell(
_file );
290 fgzstreambuf::pos_type
293 pos_type ret = pos_type(off_type(-1));
303 off_type zegptr =
zTell();
304 if ( zegptr != off_type(-1) )
306 if ( way_r == std::ios_base::end )
317 off_type zeback = zegptr - ( egptr() - eback() );
318 off_type zgptr = zegptr - ( egptr() - gptr() );
319 off_type zngptr = off_r;
320 if ( way_r == std::ios_base::cur )
323 way_r = std::ios_base::beg;
326 if ( way_r == std::ios_base::beg )
328 if ( zeback <= zngptr && zngptr <= zegptr )
333 eback() + (zngptr-zeback),
335 ret = pos_type(zngptr);
351 fgzstreambuf::pos_type
354 off_t pos = lseek (
_fd, 0, SEEK_CUR);
pos_type zSeekTo(off_type off_r, std::ios_base::seekdir way_r)
bool zWriteFrom(const char *buffer_r, std::streamsize count_r)
int _errno
errno, valid if zError is Z_ERRNO
map< string, string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
int _fd
file descriptor of the compressed file
pos_type seekTo(off_type off_r, std::ios_base::seekdir way_r)
std::ios_base::openmode _mode
virtual int_type overflow(int_type c=traits_type::eof())
std::streamsize zReadTo(char *buffer_r, std::streamsize maxcount_r)
virtual int_type underflow()
int _zError
The zlib error code.
std::string strerror() const
Return string describing the zlib error code.
pos_type compressed_tell() const
Tell the file position in the compressed file.
Streambuffer reading or writing gzip files.
fgzstreambuf * open(const char *name_r, std::ios_base::openmode mode_r=std::ios_base::in)