MCPcopy
hub / github.com/saltstack/salt / get_file_checksum

Function get_file_checksum

tools/utils/__init__.py:343–358  ·  view source on GitHub ↗
(fpath: pathlib.Path, hash_name: str)

Source from the content-addressed store, hash-verified

341
342
343def get_file_checksum(fpath: pathlib.Path, hash_name: str) -> str:
344 with fpath.open("rb") as rfh:
345 try:
346 digest = hashlib.file_digest(rfh, hash_name) # type: ignore[attr-defined]
347 except AttributeError:
348 # Python < 3.14
349 buf = bytearray(2**18) # Reusable buffer to reduce allocations.
350 view = memoryview(buf)
351 digest = getattr(hashlib, hash_name)()
352 while True:
353 size = rfh.readinto(buf)
354 if size == 0:
355 break # EOF
356 digest.update(view[:size])
357 hexdigest: str = digest.hexdigest()
358 return hexdigest
359
360
361def download_file(

Callers

nothing calls this directly

Calls 2

openMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected