MCPcopy Create free account
hub / github.com/alibaba/GraphScope / _hash_file

Function _hash_file

python/graphscope/dataset/io_utils.py:70–86  ·  view source on GitHub ↗

Calculates a file sha256 or md5 hash. Examples: ..code:: python >>> _hash_file("/path/to/file") "ccd128ab673e5d7dd1cceeaa4ba5d65b67a18212c4a27b0cd090359bd7042b10"

(fpath, algorithm="sha256", chunk_size=65535)

Source from the content-addressed store, hash-verified

68
69
70def _hash_file(fpath, algorithm="sha256", chunk_size=65535):
71 """Calculates a file sha256 or md5 hash.
72
73 Examples:
74 ..code:: python
75
76 >>> _hash_file("/path/to/file")
77 "ccd128ab673e5d7dd1cceeaa4ba5d65b67a18212c4a27b0cd090359bd7042b10"
78 """
79 if isinstance(algorithm, str):
80 hasher = _resolve_hasher(algorithm)
81 else:
82 hasher = algorithm
83 with open(fpath, "rb") as file:
84 for chunk in iter(lambda: file.read(chunk_size), b""):
85 hasher.update(chunk)
86 return hasher.hexdigest()
87
88
89def _extract_archive(fpath, path=".", archive_format="auto"):

Callers 1

validate_fileFunction · 0.85

Calls 4

_resolve_hasherFunction · 0.85
openFunction · 0.85
readMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected