37 if (!
open(fileName, 1, err_msg))
39 "Error trying to open file: '%s', error: '%s'", fileName.c_str(),
45 const string& fileName,
int compress_level,
50 if (
m_f->f) gzclose(
m_f->f);
53 m_f->f = gzopen(fileName.c_str(),
format(
"wb%i", compress_level).c_str());
54 if (
m_f->f ==
nullptr && error_msg)
55 error_msg.value().get() =
std::string(strerror(errno));
56 return m_f->f !=
nullptr;
82 return gzwrite(
m_f->f, const_cast<void*>(Buffer), Count);
91 return gztell(
m_f->f);
96 return m_f->f !=
nullptr;
TSeekOrigin
Used in CStream::Seek.
#define THROW_EXCEPTION(msg)
bool open(const std::string &fileName, int compress_level=1, mrpt::optional_ref< std::string > error_msg=std::nullopt)
Open a file for write, choosing the compression level.
uint64_t getPosition() const override
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
std::optional< std::reference_wrapper< T > > optional_ref
Shorter name for std::optional<std::reference_wrapper<T>>
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
GLsizei const GLchar ** string
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
uint64_t getTotalBytesCount() const override
This method is not implemented in this class.
void close()
Close the file.
unsigned __int64 uint64_t
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
uint64_t Seek(int64_t, CStream::TSeekOrigin=sFromBeginning) override
This method is not implemented in this class.
pimpl< T > make_impl(Args &&... args)
CFileGZOutputStream()
Constructor, without opening the file.
Saves data to a file and transparently compress the data using the given compression level...
~CFileGZOutputStream() override
Destructor.