1 #pragma once 2 3 #include <cstdint> // uint8_t 4 #include <fstream> // ifstream, istreambuf_iterator, ios 5 #include <vector> // vector 6 7 namespace utils 8 { 9 read_binary_file(const std::string & filename)10inline std::vector<std::uint8_t> read_binary_file(const std::string& filename) 11 { 12 std::ifstream file(filename, std::ios::binary); 13 file.unsetf(std::ios::skipws); 14 15 file.seekg(0, std::ios::end); 16 const auto size = file.tellg(); 17 file.seekg(0, std::ios::beg); 18 19 std::vector<std::uint8_t> byte_vector; 20 byte_vector.reserve(static_cast<std::size_t>(size)); 21 byte_vector.insert(byte_vector.begin(), std::istream_iterator<std::uint8_t>(file), std::istream_iterator<std::uint8_t>()); 22 return byte_vector; 23 } 24 25 } // namespace utils 26