CCF
Loading...
Searching...
No Matches
Functions
files Namespace Reference

Functions

bool exists (const std::string &file)
 Checks if a path exists.
 
std::vector< uint8_t > slurp (const std::string &file, bool optional=false)
 Tries to read a file as byte vector.
 
std::string slurp_string (const std::string &file, bool optional=false)
 Tries to read a file as string.
 
std::optional< std::string > try_slurp_string (const std::string &file)
 
nlohmann::json slurp_json (const std::string &file, bool optional=false)
 Tries to read a file as JSON.
 
void dump (const std::vector< uint8_t > &data, const std::string &file)
 Writes the content of a vector to a file.
 
void dump (const std::string &data, const std::string &file)
 Writes the content of a string to a file.
 
void rename (const fs::path &src, const fs::path &dst)
 

Function Documentation

◆ dump() [1/2]

void files::dump ( const std::string &  data,
const std::string &  file 
)

Writes the content of a string to a file.

Parameters
datastring to write
filethe path

◆ dump() [2/2]

void files::dump ( const std::vector< uint8_t > &  data,
const std::string &  file 
)

Writes the content of a vector to a file.

Parameters
datavector to write
filethe path

◆ exists()

bool files::exists ( const std::string &  file)

Checks if a path exists.

Parameters
filefile to check
Returns
true if the file exists.

◆ rename()

void files::rename ( const fs::path &  src,
const fs::path &  dst 
)

◆ slurp()

std::vector< uint8_t > files::slurp ( const std::string &  file,
bool  optional = false 
)

Tries to read a file as byte vector.

Parameters
filethe path
optionaldetermines behaviour in the case where the file does not exist. If true, an empty vector is returned. If false, the process exits
Returns
vector<uint8_t> the file contents as bytes.

◆ slurp_json()

nlohmann::json files::slurp_json ( const std::string &  file,
bool  optional = false 
)

Tries to read a file as JSON.

Parameters
filethe path
optionaldetermines behaviour in the case where the file does not exist. If true, an empty JSON object is returned. If false, the process exits
Returns
nlohmann::json JSON object containing the parsed file

◆ slurp_string()

std::string files::slurp_string ( const std::string &  file,
bool  optional = false 
)

Tries to read a file as string.

Parameters
filethe path
optionaldetermines behaviour in the case where the file does not exist. If true, an empty vector is returned. If false, the process exits
Returns
std::string the file contents as a string.

◆ try_slurp_string()

std::optional< std::string > files::try_slurp_string ( const std::string &  file)