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