校验两个文件的一致性

要求:大文件校验
import os
import hashlib
def func(path):
    file_size = os.path.getsize(path)
    obj = hashlib.md5()
    with open(path,mode='rb')as f:
        while file_size > 1024:
            content1 = f.read(1024)
            file_size -= 1024
            obj.update(content1,encoding = 'utf-8')
        else:
            content2 = f.read(file_size)
            obj.update(content2, encoding='utf-8')
            file_size = 0
    result = obj.hexdigest()
    return result
m1 = func('')
m2 = func('')
if m1 == m2:
    print('zhengque')

猜你喜欢

转载自www.cnblogs.com/liuweida/p/10858248.html