pythonwrench.hashlib module

class pythonwrench.hashlib.Hasher(*args, **kwargs)[source]

Bases: Protocol

Hasher protocol class.

block_size : int
digest_size : int
hexdigest() str[source]
name : str
update(data: Buffer, /) None[source]
pythonwrench.hashlib.hash_file(fpath: str | Path | BufferedReader, hash_type: 'sha256' | 'md5' | Hasher = 'md5', chunk_size: int | None = 268435456) str[source]

Return the hash value for a file.

Based on https://github.com/pytorch/audio/blob/v0.13.0/torchaudio/datasets/utils.py#L110

Args:

fpath: Path to existing file. hash_type: Hash name or custom Hasher algorithm. chunk_size: Max chunk size in bytes. defaults to 268435456 (256 MiB).

Returns:

Hash value as string.