计算大文件md5

pylist 641

python 计算大文件md5

# -*- coding: utf-8 -*-

from time import time
from hashlib import md5

def sum_md5(fname):
    _hash = md5()
    with open(fname, "rb") as f:
        for chunk in iter(lambda: f.read(8192), b""):  // 8k
            _hash.update(chunk)
    return _hash.hexdigest()

if __name__ == "__main__":
    file_path = '/Users/wei/Downloads/Win8pro.iso'
    t1 = time()
    print sum_md5(file_path)
    print time() - t1
登录发表评论

桂公网安备 45122402000014号