26 lines
453 B
Python
26 lines
453 B
Python
import hashlib
|
|
from io import BytesIO
|
|
|
|
|
|
def calc_hash_of_file(file):
|
|
""" calculate the hash of the file """
|
|
|
|
#read file
|
|
with open(file, 'rb') as fh:
|
|
buf = BytesIO(fh.read())
|
|
|
|
algo = hashlib.sha1()
|
|
|
|
buffer_size = 65536
|
|
buffer_size = buffer_size * 1024 * 1024
|
|
|
|
while True:
|
|
data = buf.read(buffer_size)
|
|
if not data:
|
|
break
|
|
algo.update(data)
|
|
|
|
hex = algo.hexdigest()
|
|
|
|
return hex
|