I have the following code
def GetSHA256(filename, size = 2 ** 10):
import hashlib
h = hashlib.sha256()
with open(filename, 'rb') as f:
for byte_block in iter(lambda: f.read(size * h.block_size), b""):
h.update(byte_block)
return h.hexdigest()
I want to choose an optimal chunk-size. However, from what I could find people tend to optimise by hand. E.g. here and here. Is there a way how this can be done better? Or is there a library that has thought about this question?