小编Pet*_*ter的帖子

在为Windows操作系统中的大文件计算SHA-1哈希时,Python崩溃

我想知道我是否可以对这个python脚本有一些新的眼光.它适用于中小型文件,但是大型文件(4-8GB左右)在运行几分钟后会出现无法解决的崩溃.

这里有压缩脚本

要么:

import sys
import msvcrt
import hashlib

#Print the file name (and its location) to be hashed  
print 'File:  ' + str(sys.argv[1])

#Set "SHA1Hash" equal to SHA-1 hash
SHA1Hash = hashlib.sha1()

#Open file specified by "sys.argv[1]" in read only (r) and binary (b) mode
File = open(sys.argv[1], 'rb')

#Get the SHA-1 hash for the contents of the specified file
SHA1Hash.update(File.read())

#Close the file
File.close()

#Set "SHA1HashBase16" equal to the hexadecimal of "SHA1Hash"
SHA1HashBase16 = SHA1Hash.hexdigest()

#Print the SHA-1 …
Run Code Online (Sandbox Code Playgroud)

python hash sha1 large-files

6
推荐指数
2
解决办法
2396
查看次数

标签 统计

hash ×1

large-files ×1

python ×1

sha1 ×1