我有以下代码
def GetSHA256(filename, size = 2 ** 10):
import hashlib
h = hashlib.sha256()
with open(filename, 'rb') as f:
for byte_block in iter(lambda: f.read(size * h.block_size), b""):
h.update(byte_block)
return h.hexdigest()
我想选择一个最佳的块大小。然而,据我所知,人们倾向于手工优化。例如here和here。有什么办法可以做得更好吗?还是有一个图书馆考虑过这个问题
你调查过io.DEFAULT_BUFFER_SIZE吗
根据open()的文档:
默认行为是
buffering=-1
,因此open()
更有可能读取缓冲8192块中的文件相关问题 更多 >
编程相关推荐