如何快速检查zip文件是否损坏?

发布于 2024-09-27 19:39:44 字数 137 浏览 1 评论 0原文

有谁知道如何根据文件大小快速实用地检查 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧梦荧光笔 2024-10-04 19:39:44

使用zip -T测试文件是否损坏。损坏的文件示例如下所示:

 zip -T filename.zip
        zip warning: missing end signature--probably not a zip file (did you
        zip warning: remember to use binary mode when you transferred it?)
        zip warning: (if you are trying to read a damaged archive try -F)

zip error: Zip file structure invalid (filename.zip)

Use zip -T to test the the file corrupted or not. Sample corrupted file look like this:

 zip -T filename.zip
        zip warning: missing end signature--probably not a zip file (did you
        zip warning: remember to use binary mode when you transferred it?)
        zip warning: (if you are trying to read a damaged archive try -F)

zip error: Zip file structure invalid (filename.zip)
独夜无伴 2024-10-04 19:39:44

本页第 4.3.7 节 表示压缩大小为 4 个字节,从字节 18。您可以尝试读取它并将其与文件的大小进行比较。

但是,我认为检查 zip 文件是否已损坏几乎没有用,原因有两个:

  1. 某些 zip 文件包含的字节数不仅仅是 zip 部分。例如,自解压存档具有可执行部分,但它们仍然是有效的 zip。
  2. 文件可能会在不更改其大小的情况下被损坏。

因此,我建议计算 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:

  1. Some zip files contain more bytes than just the zip part. For example, self-extracting archives have an executable part yet they're still valid zip.
  2. The file can be corrupted without changing its size.

So, I suggest calculating the CRC for a guaranteed method of checking for corruption.

全部不再 2024-10-04 19:39:44

这可能是一个迟到的答案,但如果您使用 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

酷到爆炸 2024-10-04 19:39:44

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.

帝王念 2024-10-04 19:39:44

要“确定”检查整个存档,您需要提取所有数据(因为存储在存档中的 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文