From 8fe443d92926c851fc20035b63462e7314563163 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 May 2025 08:53:21 +1200 Subject: [PATCH] . --- src/hash.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/hash.cpp b/src/hash.cpp index 564b9dd..c466789 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -1,4 +1,5 @@ #include "hash.hpp" +#define XXH_INLINE_ALL #include "xxhash.hpp" #include #include @@ -18,7 +19,15 @@ std::string hash_data(const std::string& data) { std::string hash_file(const std::string& path) { std::ifstream file(path, std::ios::binary); if (!file) return ""; - std::ostringstream oss; - oss << file.rdbuf(); - return hash_data(oss.str()); + XXH64_state_t* state = XXH64_createState(); + XXH64_reset(state, 0); + char buf[4096]; + while (file) { + file.read(buf, sizeof(buf)); + std::streamsize n = file.gcount(); + if (n > 0) XXH64_update(state, buf, static_cast(n)); + } + uint64_t h = XXH64_digest(state); + XXH64_freeState(state); + return to_hex64(h); } \ No newline at end of file