Debian Codegraph @

src/auditwheel/hashfile.py

raw
1 from __future__ import annotations
2
3 import hashlib
4 from typing import BinaryIO
5
6
7 def hashfile(afile: BinaryIO, blocksize: int = 65536) -> str:
8 """Hash the contents of an open file handle with SHA256"""
9 hasher = hashlib.sha256()
10 buf = afile.read(blocksize)
11 while len(buf) > 0:
12 hasher.update(buf)
13 buf = afile.read(blocksize)
14 return hasher.hexdigest()