gpt4 book ai didi

Ruby - XXhash 校验和大文件

转载 作者:太空宇宙 更新时间:2023-11-03 18:13:12 28 4
gpt4 key购买 nike

我有一个 3GB 的文件,我需要使用 ruby​​ xxhash 对其进行校验和图书馆。我遇到内存不足错误的问题。

这是导致错误的代码:

contents = File.read('some_file')
checksum = XXhash.xxh64(contents, 123918230912)

我知道像 openssldigest/sha1 这样的库有这样的更新方法:

checksum = File.open('some_file', "rb") do |io|
dig = Digest::SHA1.new
buf = ""
dig.update(buf) while io.read(4096, buf)
dig
end

但是xxhash好像没有这样的方法。我如何使用 xxhash 校验大文件 (3GB+)?

感谢帮助。

最佳答案

根据自述文件,xxh64_stream 方法接受一个 IO 对象,因此您可以这样做

File.open("some_file") do |f|
XXhash.xxh32_stream(f,12345678)
end

关于Ruby - XXhash 校验和大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30335939/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com