Module qute.hash

Functions for model hashing.

Functions

def calculate_file_hash(file_path: Union[pathlib.Path, str], hash_function: str = 'sha256', chunk_size: int = 8192) ‑> str

Calculate the hash of a file.

Parameters

file_path : Union[Path, str]
The path to the file to be hashed.
hash_function : str
The name of the hash function to use (e.g., "sha256").
chunk_size : int
The size of each chunk to read from the file.

Returns

hash : str
The hexadecimal hash of the file.
def compare_file_hash(file_path: Union[pathlib.Path, str], precalculated_hash: str, hash_function: str = 'sha256', chunk_size: int = 8192) ‑> bool

Compare the hash of a file with a precalculated hash.

Parameters

file_path : str
The path to the file to be hashed.
precalculated_hash : str
The precalculated hash to compare against.
hash_function : str
The name of the hash function to use (e.g., "sha256").
chunk_size : int
The size of each chunk to read from the file.

Returns

result : bool
True if the file hash matches the precaculated hash.
def read_hash_from_file(hash_file_path)

Read the hash value from a file.

Parameters

hash_file_path : Union[Path, str]
The path to the file containing the hash.

Returns

hash_value : str
The hash value read from the file.
def write_hash_to_file(hash_value: str, output_file_path: Union[pathlib.Path, str])

Write the hash value to a file.

Parameters

hash_value : str
he hash value to write to the file.
output_file_path : Union[Path, str]:
The full path to the file where the hash will be written.