94 std::ifstream fileStream( aFilePath, std::ios::binary );
97 throw std::runtime_error(
"Failed to open file: " + aFilePath );
99 fileStream.seekg( 0, std::ios::end );
100 const size_t fileSize =
static_cast<size_t>( fileStream.tellg() );
101 fileStream.seekg( 0, std::ios::beg );
103 const size_t bytesToRead = aLoadBytes.value_or( fileSize );
105 if( bytesToRead > fileSize )
106 throw std::runtime_error(
"Requested " + std::to_string( bytesToRead ) +
" bytes but file is "
107 + std::to_string( fileSize ) +
" bytes: " + aFilePath );
109 std::vector<uint8_t> data( bytesToRead );
110 fileStream.read(
reinterpret_cast<char*
>( data.data() ), bytesToRead );
112 if(
static_cast<size_t>( fileStream.gcount() ) != bytesToRead )
113 throw std::runtime_error(
"Short read from file: " + aFilePath );