如何快速检查 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.
提前致谢.
第 4.3.7 节本页的说压缩后的大小是从第 18 个字节开始的 4 个字节.您可以尝试读取它并将其与文件的大小进行比较.
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.
但是,我认为检查 zip 文件是否损坏几乎没有用,原因有两个:
However, I think it's pretty much useless for checking if the zip file is corrupted for two reasons:
- 某些 zip 文件包含的字节数多于 zip 部分.例如,自解压档案有一个可执行部分,但它们仍然是有效的 zip.
- 文件可以在不改变大小的情况下损坏.
- 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.
- The file can be corrupted without changing its size.
因此,我建议计算 CRC 以确保检查损坏的方法.
So, I suggest calculating the CRC for a guaranteed method of checking for corruption.