test: Update 19 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 34s
Build-Test-Publish / build (linux/arm64) (push) Successful in 44s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 8s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 8s
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 34s
Build-Test-Publish / build (linux/arm64) (push) Successful in 44s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 8s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 8s
This commit is contained in:
33
dehydrate/src/hash.cpp
Normal file
33
dehydrate/src/hash.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "hash.hpp"
|
||||
#define XXH_INLINE_ALL
|
||||
#include "xxhash.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
static std::string to_hex64(uint64_t value) {
|
||||
std::ostringstream oss;
|
||||
oss << std::hex << std::setw(16) << std::setfill('0') << value;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string hash_data(const std::string& data) {
|
||||
uint64_t h = XXH3_64bits(data.data(), data.size());
|
||||
return to_hex64(h);
|
||||
}
|
||||
|
||||
std::string hash_file(const std::string& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) return "";
|
||||
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<size_t>(n));
|
||||
}
|
||||
uint64_t h = XXH64_digest(state);
|
||||
XXH64_freeState(state);
|
||||
return to_hex64(h);
|
||||
}
|
Reference in New Issue
Block a user