namespace mrpt::io

Overview

namespace io {

// namespaces

namespace mrpt::io::internal;
namespace mrpt::io::zip;

// typedefs

typedef int TFileOpenModes;

// enums

enum
{
    fomRead   = 1,
    fomWrite  = 2,
    fomAppend = 4,
};

enum CompressionType;
enum CompressionType;
enum OpenMode;

// structs

struct CompressionOptions;
struct VectorTextFileOptions;

// classes

class CCompressedInputStream;
class CCompressedOutputStream;
class CFileGZInputStream;
class CFileGZOutputStream;
class CFileInputStream;
class CFileOutputStream;
class CFileStream;
class CMemoryStream;
class CPipe;
class CPipeBaseEndPoint;
class CPipeReadEndPoint;
class CPipeWriteEndPoint;
class CStream;
class CTextFileLinesParser;

// global functions

template <typename MATRIX>
void load_csv(const std::string& path, MATRIX& M);

CompressionType detect_compression(const std::string& filePath);
std::string lazy_load_absolute_path(const std::string& relativeOrAbsolutePath);
const std::string& getLazyLoadPathBase();
void setLazyLoadPathBase(const std::string& path);
void registerAllClasses_mrpt_io();
bool vectorToBinaryFile(const std::vector<uint8_t>& vec, const std::string& fileName);
bool loadBinaryFile(std::vector<uint8_t>& out_data, const std::string& fileName);
std::optional<std::vector<uint8_t>> loadBinaryFile(const std::string& fileName);
bool loadTextFile(std::vector<std::string>& o, const std::string& fileName);
std::optional<std::vector<std::string>> loadTextFile(const std::string& fileName);
std::string file_get_contents(const std::string& fileName);

bool vectorToTextFile(
    const std::vector<float>& vec,
    const std::string& fileName,
    const VectorTextFileOptions& opts = {}
    );

bool vectorToTextFile(
    const std::vector<double>& vec,
    const std::string& fileName,
    const VectorTextFileOptions& opts = {}
    );

bool vectorToTextFile(
    const std::vector<int>& vec,
    const std::string& fileName,
    const VectorTextFileOptions& opts = {}
    );

bool vectorToTextFile(
    const std::vector<size_t>& vec,
    const std::string& fileName,
    const VectorTextFileOptions& opts = {}
    );

bool vectorToTextFile(
    const std::vector<float>& vec,
    const std::string& fileName,
    bool append,
    bool byRows = false
    );

bool vectorToTextFile(
    const std::vector<double>& vec,
    const std::string& fileName,
    bool append,
    bool byRows = false
    );

bool vectorToTextFile(
    const std::vector<int>& vec,
    const std::string& fileName,
    bool append,
    bool byRows = false
    );

bool vectorToTextFile(
    const std::vector<size_t>& vec,
    const std::string& fileName,
    bool append,
    bool byRows = false
    );

template <class EIGEN_MATRIX>
bool vectorToTextFile(
    const EIGEN_MATRIX& vec,
    const std::string& fileName
    );

bool vectorNumericFromTextFile(
    std::vector<double>& vec,
    const std::string& fileName,
    const bool byRows = false
    );

} // namespace io

Typedefs

typedef int TFileOpenModes

File open modes are used in CFileStream Posible values are:

  • fomRead

  • fomWrite (creates the file if it didn’t exist, otherwise truncates it).

  • fomAppend (creates the file if it didn’t exist)

Global Functions

CompressionType detect_compression(const std::string& filePath)

Detects whether a file is gzip- or Zstandard-compressed, or none.

This function inspects the magic bytes at the beginning of the file to identify well-known compression formats:

  • Gzip : magic bytes 0x1F 0x8B

  • Zstandard : magic bytes 0x28 0xB5 0x2F 0xFD

  • Zstandard skippable frames : 0x2A 0x4D 0x18 0x5x

The detection is constant-time and does not attempt full decompression.

Parameters:

filePath

Path to the file to inspect.

Returns:

The detected compression type, or CompressionType::None if the format is not recognized.