25 lines
801 B
C++
25 lines
801 B
C++
#include "core/resources/resource_helper.hpp"
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
namespace Resource::Helper {
|
|
|
|
auto loadFile(const std::string& filepath) -> std::vector<std::uint8_t> {
|
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
|
if (!file) {
|
|
std::cerr << "Resource::Helper: cannot open " << filepath << '\n';
|
|
return {};
|
|
}
|
|
std::streamsize size = file.tellg();
|
|
file.seekg(0, std::ios::beg);
|
|
std::vector<std::uint8_t> data(static_cast<std::size_t>(size));
|
|
if (!file.read(reinterpret_cast<char*>(data.data()), size)) {
|
|
std::cerr << "Resource::Helper: failed to read " << filepath << '\n';
|
|
return {};
|
|
}
|
|
return data;
|
|
}
|
|
|
|
} // namespace Resource::Helper
|