| 173 | }; |
| 174 | |
| 175 | void openFile(const std::string &file_name, uint64_t offset, std::ifstream &input_stream, const std::shared_ptr<logging::Logger> &logger) { |
| 176 | logger->log_debug("Opening %s", file_name); |
| 177 | input_stream.open(file_name.c_str(), std::fstream::in | std::fstream::binary); |
| 178 | if (!input_stream.is_open() || !input_stream.good()) { |
| 179 | input_stream.close(); |
| 180 | throw Exception(FILE_OPERATION_EXCEPTION, "Could not open file: " + file_name); |
| 181 | } |
| 182 | if (offset != 0U) { |
| 183 | input_stream.seekg(offset, std::ifstream::beg); |
| 184 | if (!input_stream.good()) { |
| 185 | logger->log_error("Seeking to %" PRIu64 " failed for file %s (does file/filesystem support seeking?)", offset, file_name); |
| 186 | throw Exception(FILE_OPERATION_EXCEPTION, "Could not seek file " + file_name + " to offset " + std::to_string(offset)); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | constexpr std::size_t BUFFER_SIZE = 4096; |
| 192 | |