25 lines
719 B
Python
25 lines
719 B
Python
#!/usr/bin/env python3
|
|
"""SHA256 file hash calculator - quick utility for integrity verification."""
|
|
import hashlib
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def calc_sha256(file_path: str) -> str:
|
|
"""Calculate SHA256 hash of a file."""
|
|
h = hashlib.sha256()
|
|
with open(file_path, 'rb') as f:
|
|
for chunk in iter(lambda: f.read(8192), b''):
|
|
h.update(chunk)
|
|
return h.hexdigest()
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print("Usage: sha256_tool.py <file>", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
path = Path(sys.argv[1])
|
|
if not path.exists():
|
|
print(f"Error: {path} not found", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
print(calc_sha256(str(path))) |