24 static bool Exists(
const fs::path& filePath) {
25 std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
34 static std::vector<uint8_t> ReadAllBytes(
const fs::path& filePath) {
35 std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
38 return std::vector<uint8_t>();
40 int32_t fileSize = (int32_t)file.tellg();
42 char* data =
new char[fileSize];
43 file.read(data, fileSize);
44 std::vector<uint8_t> result = std::vector<uint8_t>(data, data + fileSize);
55 static std::string ReadAllText(
const fs::path& filePath) {
56 std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
57 int32_t fileSize = (int32_t)file.tellg();
59 char* data =
new char[fileSize + 1];
60 memset(data, 0, fileSize + 1);
61 file.read(data, fileSize);
62 std::string str = std::string((
const char*)data);
73 static std::vector<std::string> ReadAllLines(
const fs::path& filePath) {
74 std::string text = ReadAllText(filePath);
75 std::vector<std::string> lines = StringHelper::Split(text,
"\n");
86 static void WriteAllBytes(
const fs::path& filePath,
const std::vector<uint8_t>& data) {
87 if (!Directory::Exists(Path::GetDirectoryName(filePath))) {
88 Directory::MakeDirectory(Path::GetDirectoryName(filePath).
string());
90 std::ofstream file(filePath, std::ios::binary);
91 file.write((
char*)data.data(), data.size());
100 static void WriteAllBytes(
const std::string& filePath,
const std::vector<char>& data) {
101 if (!Directory::Exists(Path::GetDirectoryName(filePath))) {
102 Directory::MakeDirectory(Path::GetDirectoryName(filePath).
string());
105 std::ofstream file(filePath, std::ios::binary);
106 file.write((
char*)data.data(), data.size());
116 static void WriteAllBytes(
const std::string& filePath,
const char* data,
int dataSize) {
117 if (!Directory::Exists(Path::GetDirectoryName(filePath))) {
118 Directory::MakeDirectory(Path::GetDirectoryName(filePath).
string());
120 std::ofstream file(filePath, std::ios::binary);
121 file.write((
char*)data, dataSize);
129 static void WriteAllText(
const fs::path& filePath,
const std::string& text) {
130 if (!Directory::Exists(Path::GetDirectoryName(filePath))) {
131 Directory::MakeDirectory(Path::GetDirectoryName(filePath).
string());
133 std::ofstream file(filePath, std::ios::out | std::ios::binary);
134 file.write(text.c_str(), text.size());