13 Star 45 Fork 13

openEuler/wsl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hash.py 701 Bytes
一键复制 编辑 原始数据 按行查看 历史
import hashlib
import sys
def calculate_sha256(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, 'rb') as file:
for chunk in iter(lambda: file.read(4096), b''):
sha256_hash.update(chunk)
return sha256_hash.hexdigest()
def write_sha256_file(file_path, sha256sum):
output_file = file_path + '.sha256sum'
with open(output_file, 'w', newline='\n') as file:
file.write(sha256sum + ' ' + file_path)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f"usage: {__file__} <file_to_hash>")
sys.exit(1)
file_path = sys.argv[1]
sha256sum = calculate_sha256(file_path)
write_sha256_file(file_path, sha256sum)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/wsl.git
git@gitee.com:openeuler/wsl.git
openeuler
wsl
wsl
master

搜索帮助