MCPcopy Create free account
hub / github.com/comaps/comaps / Calculate

Method Calculate

libs/coding/sha1.cpp:34–60  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

32
33// static
34SHA1::Hash SHA1::Calculate(std::string const & filePath)
35{
36 try
37 {
38 base::FileData file(filePath, base::FileData::Op::READ);
39 uint64_t const fileSize = file.Size();
40
41 boost::uuids::detail::sha1 sha1;
42
43 uint64_t currSize = 0;
44 uint32_t constexpr kFileBufferSize = 8192;
45 unsigned char buffer[kFileBufferSize];
46 while (currSize < fileSize)
47 {
48 auto const toRead = std::min(kFileBufferSize, static_cast<uint32_t>(fileSize - currSize));
49 file.Read(currSize, buffer, toRead);
50 sha1.process_bytes(buffer, toRead);
51 currSize += toRead;
52 }
53 return ExtractHash(sha1);
54 }
55 catch (Reader::Exception const & ex)
56 {
57 LOG(LERROR, ("Error reading file:", filePath, ex.what()));
58 }
59 return {};
60}
61
62// static
63std::string SHA1::CalculateBase64(std::string const & filePath)

Callers

nothing calls this directly

Calls 4

ExtractHashFunction · 0.85
SizeMethod · 0.45
ReadMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected