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