| 39 | } |
| 40 | |
| 41 | Unit FileToVector(const std::string &Path, size_t MaxSize, bool ExitOnError) { |
| 42 | std::ifstream T(Path, std::ios::binary); |
| 43 | if (ExitOnError && !T) { |
| 44 | Printf("No such directory: %s; exiting\n", Path.c_str()); |
| 45 | exit(1); |
| 46 | } |
| 47 | |
| 48 | T.seekg(0, T.end); |
| 49 | auto EndPos = T.tellg(); |
| 50 | if (EndPos < 0) return {}; |
| 51 | size_t FileLen = EndPos; |
| 52 | if (MaxSize) |
| 53 | FileLen = std::min(FileLen, MaxSize); |
| 54 | |
| 55 | T.seekg(0, T.beg); |
| 56 | Unit Res(FileLen); |
| 57 | T.read(reinterpret_cast<char *>(Res.data()), FileLen); |
| 58 | return Res; |
| 59 | } |
| 60 | |
| 61 | std::string FileToString(const std::string &Path) { |
| 62 | std::ifstream T(Path, std::ios::binary); |
no test coverage detected