要求:大文件校验
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')

 

相关文章:

  • 2022-01-06
  • 2022-12-23
  • 2021-08-29
  • 2021-10-22
  • 2022-12-23
  • 2021-10-31
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2022-01-06
  • 2022-02-02
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案