Sunshine latest
Self-hosted game stream host for Moonlight.
file_handler Namespace Reference

Responsible for file handling functions. More...

Functions

std::string get_parent_directory (const std::string &path)
 Get the parent directory of a file or directory.
 
bool make_directory (const std::string &path)
 Make a directory.
 
std::string read_file (const char *path)
 Read a file to string.
 
int write_file (const char *path, const std::string_view &contents)
 Writes a file.
 

Detailed Description

Responsible for file handling functions.

Function Documentation

◆ get_parent_directory()

std::string file_handler::get_parent_directory ( const std::string & path)

Get the parent directory of a file or directory.

Parameters
pathThe path of the file or directory.
Returns
The parent directory.

Examples

std::string parent_dir = get_parent_directory("path/to/file");
std::string get_parent_directory(const std::string &path)
Get the parent directory of a file or directory.
Definition file_handler.cpp:15

◆ make_directory()

bool file_handler::make_directory ( const std::string & path)

Make a directory.

Parameters
pathThe path of the directory.
Returns
true on success, false on failure.

Examples

bool dir_created = make_directory("path/to/directory");
bool make_directory(const std::string &path)
Make a directory.
Definition file_handler.cpp:26

◆ read_file()

std::string file_handler::read_file ( const char * path)

Read a file to string.

Parameters
pathThe path of the file.
Returns
The contents of the file.

Examples

std::string contents = read_file("path/to/file");
std::string read_file(const char *path)
Read a file to string.
Definition file_handler.cpp:35

◆ write_file()

int file_handler::write_file ( const char * path,
const std::string_view & contents )

Writes a file.

Parameters
pathThe path of the file.
contentsThe contents to write.
Returns
0 on success, -1 on failure.

Examples

int write_status = write_file("path/to/file", "file contents");
int write_file(const char *path, const std::string_view &contents)
Writes a file.
Definition file_handler.cpp:45