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)
| 136 | |
| 137 | |
| 138 | def 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 | |
| 157 | def download_file( # noqa: C901 |
no test coverage detected