spark: add SHA256 checksum utility

This commit is contained in:
spark committed 2026-10-29 19:19:54 +00:00
1 parent 10075e2d37
commit 6b8b58ed00
1 file changed
+31
+31
View File
@@ -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 <filepath>")
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())