diff options
Diffstat (limited to 'client/src/util/io.cpp')
| -rw-r--r-- | client/src/util/io.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/client/src/util/io.cpp b/client/src/util/io.cpp index 019ec3f..f6048ba 100644 --- a/client/src/util/io.cpp +++ b/client/src/util/io.cpp @@ -10,3 +10,25 @@ void io::init() { logger = std::make_shared<spdlog::logger>("client", sink); } + +bool io::read_file(const std::string_view name, std::vector<char>& out) { + std::ifstream file(name.data(), std::ios::binary); + if (!file.good()) { + io::logger->error("{} isnt valid.", name); + return false; + } + + file.unsetf(std::ios::skipws); + + file.seekg(0, std::ios::end); + const size_t size = file.tellg(); + file.seekg(0, std::ios::beg); + + out.resize(size); + + file.read(&out[0], size); + + file.close(); + + return true; +} |