如何快速检查zip文件是否损坏?
有谁知道如何根据文件大小快速实用地检查 zip 文件是否已损坏?理想情况下,检查 zip 是否损坏的最佳方法是进行 CRC 检查,但这可能需要很长时间,尤其是在存在大量大型 zip 文件的情况下。我很高兴能够快速检查文件大小或标题。
提前致谢。
Does anyone have any ideas for how to pragmatically quickly check if a zip file is corrupted based on file size? Ideally the best way to check if a zip is corrupted is to do a CRC check but this can take a long time especially if there is a lot of large zip files. I would be happy just to be able to do a quick file size or header check.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
zip -T
测试文件是否损坏。损坏的文件示例如下所示:Use
zip -T
to test the the file corrupted or not. Sample corrupted file look like this:本页第 4.3.7 节 表示压缩大小为 4 个字节,从字节 18。您可以尝试读取它并将其与文件的大小进行比较。
但是,我认为检查 zip 文件是否已损坏几乎没有用,原因有两个:
因此,我建议计算 CRC,作为检查损坏的有保证的方法。
Section 4.3.7 of this page says that the compressed size is 4 bytes starting from byte 18. You could try reading that and comparing it to the size to the file.
However, I think it's pretty much useless for checking if the zip file is corrupted for two reasons:
So, I suggest calculating the CRC for a guaranteed method of checking for corruption.
这可能是一个迟到的答案,但如果您使用 Windows 命令行,并且安装了 7zip,只需将其添加到您的系统路径并运行以下命令:
7z t file.zip
This might be a late answer, but if you are on the windows command line, and have 7zip installed, just add it to your system PATH and run this:
7z t file.zip
DotNetZip 是一个用于处理 .NET 语言中的 zip 文件的免费开源库,支持 CheckZip() 方法可以完成您想要的操作。您可以选择多种级别的保证。基础级别仅检查元数据的一致性。最完整的级别将 zip 文件完全提取到位桶中,以验证实际的压缩数据没有损坏。
DotNetZip, a free open source library for handling zip files in .NET languages, supports a CheckZip() method that does what you want. There are various levels of assurance available at your option. The basic level just checks consistency of metadata. The most complete level does a full extraction of the zip file into a bitbucket to verify that the actual compressed data is not corrupted.
要“确定”检查整个存档,您需要提取所有数据(因为存储在存档中的 CRC 是根据未压缩的数据计算的),并且即使在此之后您也无法 100% 确定它没有损坏(因为 CRC很好,但不能保证数据不被更改)。
To check the whole archive 'for sure' you need to extract all data (since CRC, stored in archive, is calculated over uncompressed data), and, even after that you cannot be sure for 100% that it is not corrupted (because CRC is good, but not-guarantee that data was not altered).