class mrpt::io::CFileGZOutputStream

Saves data to a file and transparently compress the data using the given compression level.

The generated files are in gzip format (“file.gz”). This class requires compiling MRPT with wxWidgets. If wxWidgets is not available then the class is actually mapped to the standard CFileOutputStream

See also:

CFileOutputStream

#include <mrpt/io/CFileGZOutputStream.h>

class CFileGZOutputStream: public mrpt::io::CStream
{
public:
    // structs

    struct Impl;

    // construction

    CFileGZOutputStream(const std::string& fileName);
    CFileGZOutputStream();
    CFileGZOutputStream(const CFileGZOutputStream&);

    //
methods

    CFileGZOutputStream& operator = (const CFileGZOutputStream&);

    bool open(
        const std::string& fileName,
        int compress_level = 1,
        mrpt::optional_ref<std::string> error_msg = std::nullopt
        );

    void close();
    bool fileOpenCorrectly() const;
    bool is_open();
    virtual uint64_t getPosition() const;
    virtual uint64_t Seek(int64_t, CStream::TSeekOrigin = sFromBeginning);
    virtual uint64_t getTotalBytesCount() const;
    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

CFileGZOutputStream(const std::string& fileName)

Constructor: opens an output file with compression level = 1 (minimum, fastest).

Parameters:

fileName

The file to be open in this stream

See also:

open

CFileGZOutputStream()

Constructor, without opening the file.

See also:

open

Methods

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.

Parameters:

fileName

The file to be open in this stream

compress_level

0:no compression, 1:fastest, 9:best

Returns:

true on success, false on any error.

void close()

Close 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.

virtual uint64_t getPosition() const

Method for getting the current cursor position, 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 uint64_t getTotalBytesCount() const

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.