diff --git a/include/vmutils.hpp b/include/vmutils.hpp index 163d755..4212a64 100644 --- a/include/vmutils.hpp +++ b/include/vmutils.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,23 @@ inline void init() { } } +inline bool open_binary_file(const std::string &file, + std::vector &data) { + std::ifstream fstr(file, std::ios::binary); + if (!fstr.is_open()) return false; + + fstr.unsetf(std::ios::skipws); + fstr.seekg(0, std::ios::end); + + const auto file_size = fstr.tellg(); + + fstr.seekg(NULL, std::ios::beg); + data.reserve(static_cast(file_size)); + data.insert(data.begin(), std::istream_iterator(fstr), + std::istream_iterator()); + return true; +} + /// /// utils pertaining to native registers... ///