Calculates a file sha256 or md5 hash. Examples: ..code:: python >>> _hash_file("/path/to/file") "ccd128ab673e5d7dd1cceeaa4ba5d65b67a18212c4a27b0cd090359bd7042b10"
(fpath, algorithm="sha256", chunk_size=65535)
| 68 | |
| 69 | |
| 70 | def _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 | |
| 89 | def _extract_archive(fpath, path=".", archive_format="auto"): |
no test coverage detected