在为Windows操作系统中的大文件计算SHA-1哈希时,Python崩溃
发布时间:2020-12-14 04:19:35 所属栏目:Windows 来源:网络整理
导读:我想知道我是否可以对这个 python脚本有一些新的眼光.它适用于中小型文件,但是大型文件(4-8GB左右)在运行几分钟后会出现无法解决的崩溃. Zipped script here 要么: import sysimport msvcrtimport hashlib#Print the file name (and its location) to be ha
我想知道我是否可以对这个
python脚本有一些新的眼光.它适用于中小型文件,但是大型文件(4-8GB左右)在运行几分钟后会出现无法解决的崩溃.
Zipped script here 要么: 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 (hexadecimal) hash of the file print 'SHA-1: ' + SHA1HashBase16 #Make a blank line print ' ' #Print "Press any key to continue..." print 'Press any key to continue...' #"Press any key to continue..." delay char=0 while not char: char=msvcrt.getch() * 更新 * 使用python脚本计算大文件的SHA-1哈希值.感谢Ignacio Vazquez-Abrams指出错误和Tom Zych的代码. Zipped source here 使用简单地拖放要在脚本顶部进行哈希处理的文件.或者,您可以使用命令提示符,使用: SHA-1HashGen.py Path&File SHA-1HashGen.py是脚本的文件名,Path& File是要散列的文件的路径和文件名. 或者将脚本放入SendTo文件夹(在Windows操作系统中; shell:sendto)以将其作为右键单击选项.
停止一次阅读文件;你正在消耗系统上的所有内存.请改为读入16MB左右的块.
data = File.read(16 * 1024 * 1024) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 可以提示输入Windows服务用户名/密码吗?
- windows – 默认网关IP =路由器IP吗?
- windows-phone-7 – Vici CoolStorage便携性:Monotouch,Mo
- windows-7 – 在Windows 7下处理UNC网络共享超时的最佳方法
- windows-installer – installshield和windowsinstaller之间
- windows-xp – 如何在不进行域管理的情况下更改当前用户的域
- .net – Windows WPF或Silverlight中的VT100终端仿真
- Windows下的2017 最新版 MyEclipse启动出现:a java runtim
- windows-server-2008-r2 – 虚拟(ESXi4)Win 2k8 R2服务器在
- [图形学]VS2017中OpenGL的下载及安装中的异常
推荐文章
站长推荐
热点阅读