import hashlib from io import BytesIO def calc_hash_of_bytes(buf: BytesIO): """ calculate the hash of the file """ 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 def calc_hash_of_file(file): """ calculate the hash of the file """ #read file with open(file, 'rb') as fh: buf = BytesIO(fh.read()) hex = calc_hash_of_bytes(buf) return hex