class mrpt::io::CFileGZInputStream
Transparently opens a compressed “gz” file and reads uncompressed data from it.
If the file is not a .gz file, it silently reads data from the file.
See also:
#include <mrpt/io/CFileGZInputStream.h> class CFileGZInputStream: public mrpt::io::CStream { public: // structs struct Impl; // construction CFileGZInputStream(); CFileGZInputStream(const std::string& fileName); CFileGZInputStream(const CFileGZInputStream&); // methods CFileGZInputStream& operator = (const CFileGZInputStream&); virtual std::string getStreamDescription() const; bool open(const std::string& fileName, mrpt::optional_ref<std::string> error_msg = std::nullopt); void close(); bool fileOpenCorrectly() const; bool is_open(); bool checkEOF(); std::string filePathAtUse() const; virtual uint64_t getTotalBytesCount() const; virtual uint64_t getPosition() const; virtual uint64_t Seek(int64_t, CStream::TSeekOrigin = sFromBeginning); virtual size_t Read(void* Buffer, size_t Count); virtual size_t Write(const void* Buffer, size_t Count); };
Inherited Members
public: // methods virtual size_t Read(void* Buffer, size_t Count) = 0; virtual size_t Write(const void* Buffer, size_t Count) = 0; virtual uint64_t getTotalBytesCount() const = 0; virtual uint64_t getPosition() const = 0;
Construction
CFileGZInputStream()
Constructor without open.
CFileGZInputStream(const std::string& fileName)
Constructor and open.
Parameters:
fileName |
The file to be open in this stream |
std::exception |
If there’s an error opening the file. |
Methods
virtual std::string getStreamDescription() const
Returns a human-friendly description of the stream, e.g.
a filename.
bool open(const std::string& fileName, mrpt::optional_ref<std::string> error_msg = std::nullopt)
Opens the file for read.
Parameters:
fileName |
The file to be open in this stream |
Returns:
false if there’s an error opening the file, true otherwise
void close()
Closes the file.
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
bool is_open()
Returns true if the file was open without errors.
bool checkEOF()
Will be true if EOF has been already reached.
std::string filePathAtUse() const
Returns the path of the filename passed to open(), or empty if none.
virtual uint64_t getTotalBytesCount() const
Method for getting the total number of compressed bytes of in the file (the physical size of the compressed file).
virtual uint64_t getPosition() const
Method for getting the current cursor position in the compressed, where 0 is the first byte and TotalBytesCount-1 the last one.
virtual uint64_t Seek(int64_t, CStream::TSeekOrigin = sFromBeginning)
This method is not implemented in this class.
virtual size_t Read(void* Buffer, size_t Count)
Introduces a pure virtual method responsible for reading from the stream.
virtual size_t Write(const void* Buffer, size_t Count)
Introduces a pure virtual method responsible for writing to the stream.
Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.