| 26 | } |
| 27 | |
| 28 | std::vector<uint8_t> read_file(const std::filesystem::path & path) { |
| 29 | std::ifstream stream(path, std::ios::binary | std::ios::ate); |
| 30 | if (!stream) { |
| 31 | throw std::runtime_error("torch .bin cannot be opened: " + path.string()); |
| 32 | } |
| 33 | const std::streamsize size = stream.tellg(); |
| 34 | if (size < 0) { |
| 35 | throw std::runtime_error("torch .bin has an invalid size: " + path.string()); |
| 36 | } |
| 37 | stream.seekg(0); |
| 38 | std::vector<uint8_t> bytes(static_cast<size_t>(size)); |
| 39 | if (size > 0 && !stream.read(reinterpret_cast<char *>(bytes.data()), size)) { |
| 40 | throw std::runtime_error("torch .bin could not be read: " + path.string()); |
| 41 | } |
| 42 | return bytes; |
| 43 | } |
| 44 | |
| 45 | // ---- Minimal STORED-only ZIP reader ------------------------------------------------- |
| 46 |
no test coverage detected