Utility class providing static helpers for reading and writing files on disk.
More...
#include <FileHelper.h>
|
| static bool | Exists (const fs::path &filePath) |
| | Checks whether a file exists and is readable.
|
| |
| static std::vector< uint8_t > | ReadAllBytes (const fs::path &filePath) |
| | Reads the entire contents of a file into a byte vector.
|
| |
| static std::string | ReadAllText (const fs::path &filePath) |
| | Reads the entire contents of a file as a text string.
|
| |
| static std::vector< std::string > | ReadAllLines (const fs::path &filePath) |
| | Reads a file and splits it into lines.
|
| |
| static void | WriteAllBytes (const fs::path &filePath, const std::vector< uint8_t > &data) |
| | Writes a byte vector to a file, overwriting any existing content.
|
| |
| static void | WriteAllBytes (const std::string &filePath, const std::vector< char > &data) |
| | Writes a char vector to a file, overwriting any existing content.
|
| |
| static void | WriteAllBytes (const std::string &filePath, const char *data, int dataSize) |
| | Writes raw data to a file from a pointer and size, overwriting any existing content.
|
| |
| static void | WriteAllText (const fs::path &filePath, const std::string &text) |
| | Writes a string to a file as text, overwriting any existing content.
|
| |
Utility class providing static helpers for reading and writing files on disk.
Similar to DiskFile but lives inside the Ship namespace. All methods are static and operate directly on filesystem paths.
◆ Exists()
| static bool Ship::FileHelper::Exists |
( |
const fs::path & |
filePath | ) |
|
|
inlinestatic |
Checks whether a file exists and is readable.
- Parameters
-
| filePath | Path to the file to check. |
- Returns
- true if the file can be opened for reading, false otherwise.
◆ ReadAllBytes()
| static std::vector< uint8_t > Ship::FileHelper::ReadAllBytes |
( |
const fs::path & |
filePath | ) |
|
|
inlinestatic |
Reads the entire contents of a file into a byte vector.
- Parameters
-
| filePath | Path to the file to read. |
- Returns
- Vector containing every byte of the file, or an empty vector if the file cannot be opened.
◆ ReadAllLines()
| static std::vector< std::string > Ship::FileHelper::ReadAllLines |
( |
const fs::path & |
filePath | ) |
|
|
inlinestatic |
Reads a file and splits it into lines.
- Parameters
-
| filePath | Path to the file to read. |
- Returns
- Vector of strings, one per line.
◆ ReadAllText()
| static std::string Ship::FileHelper::ReadAllText |
( |
const fs::path & |
filePath | ) |
|
|
inlinestatic |
Reads the entire contents of a file as a text string.
- Parameters
-
| filePath | Path to the file to read. |
- Returns
- String containing the full file contents.
◆ WriteAllBytes() [1/3]
| static void Ship::FileHelper::WriteAllBytes |
( |
const fs::path & |
filePath, |
|
|
const std::vector< uint8_t > & |
data |
|
) |
| |
|
inlinestatic |
Writes a byte vector to a file, overwriting any existing content.
- Note
- Creates parent directories if they do not already exist.
- Parameters
-
| filePath | Path to the file to write. |
| data | Bytes to write. |
◆ WriteAllBytes() [2/3]
| static void Ship::FileHelper::WriteAllBytes |
( |
const std::string & |
filePath, |
|
|
const char * |
data, |
|
|
int |
dataSize |
|
) |
| |
|
inlinestatic |
Writes raw data to a file from a pointer and size, overwriting any existing content.
- Note
- Creates parent directories if they do not already exist.
- Parameters
-
| filePath | Path to the file to write. |
| data | Pointer to the data to write. |
| dataSize | Number of bytes to write. |
◆ WriteAllBytes() [3/3]
| static void Ship::FileHelper::WriteAllBytes |
( |
const std::string & |
filePath, |
|
|
const std::vector< char > & |
data |
|
) |
| |
|
inlinestatic |
Writes a char vector to a file, overwriting any existing content.
- Note
- Creates parent directories if they do not already exist.
- Parameters
-
| filePath | Path to the file to write. |
| data | Characters to write. |
◆ WriteAllText()
| static void Ship::FileHelper::WriteAllText |
( |
const fs::path & |
filePath, |
|
|
const std::string & |
text |
|
) |
| |
|
inlinestatic |
Writes a string to a file as text, overwriting any existing content.
- Parameters
-
| filePath | Path to the file to write. |
| text | String to write. |
The documentation for this class was generated from the following file: