Refactor bytes_hash function to handle string input

This commit is contained in:
Théophile Diot 2024-03-12 15:32:41 +00:00
parent d6d3950f01
commit 6f16da357a
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06

View file

@ -64,8 +64,10 @@ def file_hash(file: Union[str, Path]) -> str:
return _sha512.hexdigest()
def bytes_hash(bio: Union[bytes, BytesIO]) -> str:
if isinstance(bio, bytes):
def bytes_hash(bio: Union[str, bytes, BytesIO]) -> str:
if isinstance(bio, str):
bio = BytesIO(bio.encode("utf-8"))
elif isinstance(bio, bytes):
bio = BytesIO(bio)
assert isinstance(bio, BytesIO)