Max limit of bytes in method update of Hashlib Python module -
i trying compute md5 hash of file function hashlib.md5() hashlib module.
so writed piece of code:
buffer = 128 f = open("c:\\file.tct", "rb") m = hashlib.md5() while true: p = f.read(buffer) if len(p) != 0: m.update(p) else: break print m.hexdigest() f.close()
i noted function update faster if increase buffer variable value 64, 128, 256 , on. there upper limit cannot exceed? suppose might ram memory problem don't know.
big (≈2**40
) chunk sizes lead memoryerror
i.e., there no limit other available ram. on other hand bufsize
limited 2**31-1
on machine:
import hashlib functools import partial def md5(filename, chunksize=2**15, bufsize=-1): m = hashlib.md5() open(filename, 'rb', bufsize) f: chunk in iter(partial(f.read, chunksize), b''): m.update(chunk) return m
big chunksize
can slow small one. measure it.
i find ≈10
mb files 2**15
chunksize
fastest files i've tested.
Comments
Post a Comment