.
This commit is contained in:
parent
d26ff959f8
commit
8fe443d929
15
src/hash.cpp
15
src/hash.cpp
@ -1,4 +1,5 @@
|
|||||||
#include "hash.hpp"
|
#include "hash.hpp"
|
||||||
|
#define XXH_INLINE_ALL
|
||||||
#include "xxhash.hpp"
|
#include "xxhash.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -18,7 +19,15 @@ std::string hash_data(const std::string& data) {
|
|||||||
std::string hash_file(const std::string& path) {
|
std::string hash_file(const std::string& path) {
|
||||||
std::ifstream file(path, std::ios::binary);
|
std::ifstream file(path, std::ios::binary);
|
||||||
if (!file) return "";
|
if (!file) return "";
|
||||||
std::ostringstream oss;
|
XXH64_state_t* state = XXH64_createState();
|
||||||
oss << file.rdbuf();
|
XXH64_reset(state, 0);
|
||||||
return hash_data(oss.str());
|
char buf[4096];
|
||||||
|
while (file) {
|
||||||
|
file.read(buf, sizeof(buf));
|
||||||
|
std::streamsize n = file.gcount();
|
||||||
|
if (n > 0) XXH64_update(state, buf, static_cast<size_t>(n));
|
||||||
|
}
|
||||||
|
uint64_t h = XXH64_digest(state);
|
||||||
|
XXH64_freeState(state);
|
||||||
|
return to_hex64(h);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user