34 swap( lhs._f, rhs._f );
44 GZFile(
const std::string &filename,
const std::string &openmode )
46 _f = gzopen( filename.c_str(), openmode.c_str() );
50 std::string errormsg = gzerror( _f, &errnum );
51 throw std::runtime_error( errormsg );
63 void open(
const std::string &filename,
const std::string &openmode ) {
67 _f = gzopen( filename.c_str(), openmode.c_str() );
69 throw std::runtime_error( std::strerror(errno) );
87 int read(
char *buf,
unsigned int size ) {
89 throw std::runtime_error(
"Cannot read. File is not open." );
90 int ret = gzread( _f, (
void *)buf, size );
93 throw std::runtime_error( gzerror( _f, &errnum ) );
104 throw std::runtime_error(
"Cannot seek. File is not open." );
105 z_off_t ret = gzseek( _f, position, SEEK_SET );
107 throw std::runtime_error(
"gzseek() failed." );
112 bool isOpen() const noexcept {
return _f !=
nullptr; }
118 bool isZipped() const noexcept {
return _f ? gzdirect(_f) != 1 :
false; }
121 bool isEof() const noexcept {
return _f ? gzeof(_f) : false; }
123 uint64_t getPosition() const noexcept {
return _f ? gzoffset(_f) : 0; }
Definition: GZFile.hpp:21
int read(char *buf, unsigned int size)
Reads data from the file to a buffer.
Definition: GZFile.hpp:87
bool isOpen() const noexcept
Checks if file is open.
Definition: GZFile.hpp:112
GZFile(const std::string &filename, const std::string &openmode)
Opens the file.
Definition: GZFile.hpp:44
GZFile()=default
Default constructor. Does nothing.
void seek(size_t position)
Seeks the file position.
Definition: GZFile.hpp:102
~GZFile()
Destructor.
Definition: GZFile.hpp:57
bool isZipped() const noexcept
Tells whether the file is zipped.
Definition: GZFile.hpp:118
Definition: mainpage.dox:6