| 5 | |
| 6 | template <typename T> |
| 7 | bool read_file(const std::filesystem::path& p, std::vector<T>& out) { |
| 8 | static_assert(sizeof(T) == 1); |
| 9 | std::vector<T> ret{}; |
| 10 | |
| 11 | std::ifstream input_file{p, std::ios::binary}; |
| 12 | if (!input_file.good()) { |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | input_file.seekg(0, std::ios::end); |
| 17 | ret.resize(input_file.tellg()); |
| 18 | input_file.seekg(0, std::ios::beg); |
| 19 | |
| 20 | input_file.read(reinterpret_cast<char*>(ret.data()), ret.size()); |
| 21 | |
| 22 | out = std::move(ret); |
| 23 | |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | bool write_file(const std::filesystem::path& p, std::span<char> in) { |
| 28 | std::ofstream out{ p, std::ios::binary }; |