in torchdata/datapipes/iter/util/cacheholder.py [0:0]
def _hash_check(filepath, hash_dict, hash_type):
if filepath not in hash_dict:
return False
if hash_type == "sha256":
hash_func = hashlib.sha256()
else:
hash_func = hashlib.md5()
with open(filepath, "rb") as f:
chunk = f.read(1024 ** 2)
while chunk:
hash_func.update(chunk)
chunk = f.read(1024 ** 2)
return hash_func.hexdigest() == hash_dict[filepath]