- 论坛徽章:
- 4
|
#读取大文件
def md5Checksum(filePath):
if os.path.isdir(filePath):
return 'dir'
with open(filePath, 'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
return m.hexdigest()
def CalcSha1(filepath):
if os.path.isdir(filepath):
return 'dir'
BLOCKSIZE = 65536
hasher = hashlib.sha1()
with open(filepath, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
return (hasher.hexdigest())
'''
with open(filepath,'rb') as f:
sha1obj = hashlib.sha1()
while True:
data = f.read(8192)
if not data:
break
sha1obj.update(data)
return sha1obj.hexdigest()
''' |
|