如何进行大文件完整性检查
我需要对单个大文件进行完整性检查。我已阅读 Android 的 SHA 代码,但它需要另一个文件作为结果摘要。还有其他使用单个文件的方法吗?
我需要一个简单快速的方法。我可以将两个文件合并为一个文件吗?
文件是二进制的,文件名是固定的。我可以使用 fstat 获取文件大小。我的问题是我只能有一个文件。也许我应该使用 CRC,但它会很慢,因为它是一个大文件。
我的目标是确保 SD 卡上的文件没有损坏。我在PC上编写并在嵌入式平台上读取它。该文件大约 200 MB。
I need to do an integrity check for a single big file. I have read the SHA code for Android, but it will need one another file for the result digest. Is there another method using a single file?
I need a simple and quick method. Can I merge the two files into a single file?
The file is binary and the file name is fixed. I can get the file size using fstat. My problem is that I can only have one single file. Maybe I should use CRC, but it would be very slow because it is a large file.
My object is to ensure the file on the SD card is not corrupt. I write it on a PC and read it on an embedded platform. The file is around 200 MB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你必须以某种方式存储哈希值,没有办法绕过它。
您可以尝试将其写入文件本身(在开头或结尾),并在执行完整性检查时跳过它。这适用于 XML 文件等文件,但不适用于图像或二进制文件。
您还可以将哈希值放在文件名中,或者仅保留所有哈希值的数据库。
这实际上完全取决于您的程序的功能以及它的设置方式。
You have to store the hash somehow, no way around it.
You can try writing it to the file itself (at the beginning or end) and skip it when performing the integrity check. This can work for things like XML files, but not for images or binaries.
You can also put the hash in the filename, or just keep a database of all your hashes.
It really all depends on what your program does and how it's set up.