From f89f8250819f6c37abdf90039e022373bce05dea Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 24 Oct 2024 15:48:46 +0300 Subject: [PATCH] update files::read_bytes --- src/files/files.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/files/files.cpp b/src/files/files.cpp index 8be834b5..985cd2ba 100644 --- a/src/files/files.cpp +++ b/src/files/files.cpp @@ -75,7 +75,11 @@ std::unique_ptr files::read_bytes( const fs::path& filename, size_t& length ) { 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); length = input.tellg(); input.seekg(0, std::ios_base::beg); @@ -102,12 +106,7 @@ std::vector files::read_bytes(const fs::path& filename) { std::string files::read_string(const fs::path& filename) { size_t size; - std::unique_ptr bytes(read_bytes(filename, size)); - if (bytes == nullptr) { - throw std::runtime_error( - "could not to load file '" + filename.string() + "'" - ); - } + auto bytes = read_bytes(filename, size); return std::string((const char*)bytes.get(), size); }