| 86 | } |
| 87 | |
| 88 | std::vector<uint8_t> StdFileSystem::read_chunk(const Path &path, size_t offset, size_t count) |
| 89 | { |
| 90 | std::ifstream file{path, std::ios::binary | std::ios::ate}; |
| 91 | |
| 92 | if (!file.is_open()) |
| 93 | { |
| 94 | throw std::runtime_error("Failed to open file for reading at path: " + path.string()); |
| 95 | } |
| 96 | |
| 97 | auto size = stat_file(path).size; |
| 98 | |
| 99 | if (offset + count > size) |
| 100 | { |
| 101 | return {}; |
| 102 | } |
| 103 | |
| 104 | // read file contents |
| 105 | file.seekg(offset, std::ios::beg); |
| 106 | std::vector<uint8_t> data(count); |
| 107 | file.read(reinterpret_cast<char *>(data.data()), count); |
| 108 | |
| 109 | return data; |
| 110 | } |
| 111 | |
| 112 | void StdFileSystem::write_file(const Path &path, const std::vector<uint8_t> &data) |
| 113 | { |