PYTHON / FILE INTEGRITY

HashLab

A clear answer when file contents change.

HashLab is a Python command-line tool for file hashing and integrity checks. It calculates a SHA-256 digest for an individual file or compares the digests of two files. Chunk-based reading avoids loading the entire file into memory, including when working with large files.

Runs on
Python 3.10+
Repository created
View source on GitHub
README example
$ python3 main.py compare original.txt copy.txt
# README result for identical file contents
Integrity : OK

# README result for different file contents
Integrity : FAILED
Documented comparison command and its two possible README outcomes. No files are processed on this website. Read the original example on GitHub, opens in a new tab.

What it does

  • Calculate a SHA-256 hash for a file.
  • Compare two files through a dedicated CLI command.
  • Read files in 4096-byte chunks for memory-efficient hashing.
  • Validate file inputs and handle errors through the command-line interface.

Run the documented example

From the repository root, use python3 main.py hash file.txt to calculate one digest. To check a copy against an original, run the comparison command shown above with your own file paths. The README reports Integrity : OK when the contents produce matching hashes and Integrity : FAILED when the hashes differ. The command-line tool uses only the Python standard library.

What an integrity check tells you

A matching digest indicates that the compared contents produced the same SHA-256 hash. It does not establish whether a file came from a trusted author or is safe to open. When checking a downloaded file against a published digest, the reference digest needs to come from a source you trust. HashLab is intended for integrity verification and educational use; its output should be interpreted within that purpose.

Inside the code

HashLab updates a SHA-256 hash object as each 4096-byte chunk is read. For comparisons, it hashes both files and compares the results. The code is organized into CLI, hashing and integrity modules, with unit tests for the hashing and comparison behavior. The GitHub repository contains the implementation and test commands.