Move file handling into ChkSum class.

This commit is contained in:
2018-10-16 23:31:08 +02:00
parent 43dfdbe8b2
commit cbb602ea83
2 changed files with 14 additions and 13 deletions

View File

@@ -5,21 +5,11 @@ from grmn import ChkSum
import sys
FILE = sys.argv[1]
BLOCKSIZE = 4 * 1024
print("Reading {} ".format(FILE), end="")
csum = ChkSum()
with open(FILE, "rb") as f:
while True:
block = f.read(BLOCKSIZE)
csum.add(block)
print(".", end="", flush=True)
if len(block) < BLOCKSIZE:
print(" done.")
break
f.close()
print("Reading {} ...".format(FILE), end="", flush=True)
csum.add_from_file(FILE, print_progress=True)
print(" done.")
print("Sum of all bytes: {:02x}".format(csum.get_sum()))
print("Last byte: {:02x}".format(csum.get_last_byte()))