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

Function validate_file

python/graphscope/dataset/io_utils.py:138–154  ·  view source on GitHub ↗

Validates a file against a sha256 or md5 hash. Args: fpath: `PathLike` object of the file being validated file_hash (str): The expected hash string of the file. The sha256 and md5 hash algorithms are both supported. algorithm (str): Hash algorithm, one of "au

(fpath, file_hash, algorithm="auto", chunk_size=65535)

Source from the content-addressed store, hash-verified

136
137
138def validate_file(fpath, file_hash, algorithm="auto", chunk_size=65535):
139 """Validates a file against a sha256 or md5 hash.
140
141 Args:
142 fpath: `PathLike` object of the file being validated
143 file_hash (str): The expected hash string of the file.
144 The sha256 and md5 hash algorithms are both supported.
145 algorithm (str): Hash algorithm, one of "auto", "sha256", or "md5".
146 The default "auto" detects the hash algorithm in use.
147 chunk_size (int): Bytes to read at a time, important for large files.
148
149 Returns (bool): Whether the file is valid.
150 """
151 hasher = _resolve_hasher(algorithm, file_hash)
152 if str(_hash_file(fpath, hasher, chunk_size)) == str(file_hash):
153 return True
154 return False
155
156
157def download_file( # noqa: C901

Callers 1

download_fileFunction · 0.85

Calls 2

_resolve_hasherFunction · 0.85
_hash_fileFunction · 0.85

Tested by

no test coverage detected