
依赖安装
# zlib 不是 python 包,需要使用如下方式安装
yum/apt-get install zlib-devel
计算方式
import zlib
def crc32(file_path):
"""
计算文件 crc32 hash 值
"""
with open(file_path, 'rb') as fh:
hash = 0
while True:
s = fh.read(65536)
if not s:
break
hash = zlib.crc32(s, hash)
return "%08X" % (hash & 0xFFFFFFFF)
类似于 MD5 的 Hash 算法,校验文件
网友评论