From 6b8b58ed0067673da067f996ed6217414a656b6a Mon Sep 17 00:00:00 2001 From: spark Date: Thu, 29 Oct 2026 19:19:54 +0000 Subject: [PATCH] spark: add SHA256 checksum utility --- wizard-work/spark/checksum.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 wizard-work/spark/checksum.py diff --git a/wizard-work/spark/checksum.py b/wizard-work/spark/checksum.py new file mode 100644 index 0000000..d91cb05 --- /dev/null +++ b/wizard-work/spark/checksum.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +"""File checksum utility - calculates SHA256 checksum of a file.""" +import sys +import hashlib + + +def sha256_checksum(filepath): + """Calculate SHA256 checksum of a file, return hex digest.""" + sha256 = hashlib.sha256() + with open(filepath, 'rb') as f: + for chunk in iter(lambda: f.read(8192), b''): + sha256.update(chunk) + return sha256.hexdigest() + + +def main(): + if len(sys.argv) != 2: + print("Usage: checksum.py ") + sys.exit(1) + filepath = sys.argv[1] + try: + result = sha256_checksum(filepath) + print(result) + return 0 + except FileNotFoundError: + print(f"Error: File '{filepath}' not found", file=sys.stderr) + return 1 + + +if __name__ == "__main__": + sys.exit(main()) \ No newline at end of file