doFolder.hashing.util module

Utility types, constants, and data structures for the hashing package.

This module defines common data types like FileHashResult, default configuration constants, and utility functions used throughout the hashing subsystem.

Added in version 2.3.0.

doFolder.hashing.util.DEFAULT_CHUNK_SIZE = 16384

Default chunk size (16KB) for reading files in chunks to optimize memory usage

doFolder.hashing.util.DEFAULT_FILE_IO_MIN_SIZE = 65536

Minimum file size threshold (64KB) to switch from content-based to streaming I/O

doFolder.hashing.util.DEFAULT_HASH_ALGORITHM = 'sha256'

Default cryptographic hash algorithm used throughout the module

doFolder.hashing.util.DEFAULT_THREAD_NUM = 4

Default number of threads for parallel hash calculation

class doFolder.hashing.util.FileHashResult(hash: str, algorithm: str, path: Path, mtime: float, calcTime: float)

Bases: object

Container for file hash calculation results.

This dataclass encapsulates all relevant information about a file’s hash calculation, including metadata about when the calculation was performed and the file’s state at that time.

hash

The calculated hash value as a hexadecimal string.

Type:

str

algorithm

The hash algorithm used (e.g., ‘sha256’, ‘md5’).

Type:

str

path

The file system path of the hashed file.

Type:

Path

mtime

File modification time (timestamp) when hash was calculated.

Type:

float

calcTime

Timestamp when the hash calculation was performed.

Type:

float

Note

The mtime attribute is crucial for cache validation, allowing the system to determine if a file has been modified since its hash was last calculated.

algorithm: str
calcTime: float
hash: str
mtime: float
path: Path
doFolder.hashing.util.normalizeAlgorithms(algorithms: str | Iterable[str]) Iterable[str]

Normalize algorithm input to a consistent iterable format.

Converts single algorithm strings to tuples for uniform processing.

Parameters:

algorithms (Union[str, Iterable[str]]) – Single algorithm or iterable of algorithms.

Returns:

Tuple of algorithm names for consistent iteration.

Return type:

Iterable[str]