mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
update files::read_bytes
This commit is contained in:
parent
edc9d9546d
commit
f89f825081
1 changed files with 6 additions and 7 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue