#include "hash.hpp" #include #include #include #include #include namespace Files { std::uint64_t getHash(const std::string& fileName, std::istream& stream) { std::uint64_t hash = std::hash {}(fileName); try { const auto start = stream.tellg(); const auto exceptions = stream.exceptions(); stream.exceptions(std::ios_base::badbit); while (stream) { std::uint64_t value = 0; stream.read(reinterpret_cast(&value), sizeof(value)); Misc::hashCombine(hash, value); } stream.exceptions(exceptions); stream.clear(); stream.seekg(start); } catch (const std::exception& e) { throw std::runtime_error("Error while reading \"" + fileName + "\" to get hash: " + std::string(e.what())); } return hash; } }