update files::read_bytes

This commit is contained in:
MihailRis 2024-10-24 15:48:46 +03:00
parent edc9d9546d
commit f89f825081

View File

@ -75,7 +75,11 @@ std::unique_ptr<ubyte[]> files::read_bytes(
const fs::path& filename, size_t& length const fs::path& filename, size_t& length
) { ) {
std::ifstream input(filename, std::ios::binary); std::ifstream input(filename, std::ios::binary);
if (!input.is_open()) return nullptr; if (!input.is_open()) {
throw std::runtime_error(
"could not to load file '" + filename.string() + "'"
);
}
input.seekg(0, std::ios_base::end); input.seekg(0, std::ios_base::end);
length = input.tellg(); length = input.tellg();
input.seekg(0, std::ios_base::beg); input.seekg(0, std::ios_base::beg);
@ -102,12 +106,7 @@ std::vector<ubyte> files::read_bytes(const fs::path& filename) {
std::string files::read_string(const fs::path& filename) { std::string files::read_string(const fs::path& filename) {
size_t size; size_t size;
std::unique_ptr<ubyte[]> bytes(read_bytes(filename, size)); auto bytes = read_bytes(filename, size);
if (bytes == nullptr) {
throw std::runtime_error(
"could not to load file '" + filename.string() + "'"
);
}
return std::string((const char*)bytes.get(), size); return std::string((const char*)bytes.get(), size);
} }