|
@@ -524,12 +524,17 @@ def md5_file(filename):
|
|
"""
|
|
"""
|
|
Return the hex string representation of the MD5 checksum of filename.
|
|
Return the hex string representation of the MD5 checksum of filename.
|
|
"""
|
|
"""
|
|
- import hashlib
|
|
|
|
- m = hashlib.md5()
|
|
|
|
|
|
+ import hashlib, mmap
|
|
|
|
|
|
with open(filename, "rb") as f:
|
|
with open(filename, "rb") as f:
|
|
- for line in f:
|
|
|
|
- m.update(line)
|
|
|
|
|
|
+ m = hashlib.md5()
|
|
|
|
+ try:
|
|
|
|
+ with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
|
|
|
|
+ for chunk in iter(lambda: mm.read(8192), b''):
|
|
|
|
+ m.update(chunk)
|
|
|
|
+ except ValueError:
|
|
|
|
+ # You can't mmap() an empty file so silence this exception
|
|
|
|
+ pass
|
|
return m.hexdigest()
|
|
return m.hexdigest()
|
|
|
|
|
|
def sha256_file(filename):
|
|
def sha256_file(filename):
|