Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
512 B
1
Indexable
Never
 inline uint8_t* ReadAsBytes(const std::string_view& path, std::size_t& file_size) noexcept {
     std::ifstream file{ path.data(), std::ifstream::in | std::ifstream::binary };
     if (!file.is_open())
         return nullptr;
     file_size = file.seekg(0, std::ios::end).tellg();
     uint8_t* data = (uint8_t*)std::malloc(file_size);

     file.seekg(0, std::ios::beg);
     file.read(reinterpret_cast<char*>(data), static_cast<std::streamsize>(file_size));
     file.close();
     return data;
 }
Leave a Comment