Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quickly check if a zip file is corrupted?

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.

like image 839
thuantta Avatar asked Oct 17 '10 17:10

thuantta


People also ask

Do zip files corrupt easily?

ZIP files can get corrupted during the download process. If the download was interrupted, due to a power outage or an unexpected program closure even for a moment, unreadable data can end up becoming part of the downloaded ZIP file and make it difficult for the data to be extracted.

What do I do with a corrupted zip file?

The best solution to the problem of a damaged Zip file is to try to obtain another copy of the file. For example, use your backup copy of the file or get a new copy from the original source. If you obtained the Zip file by downloading it, then downloading it again may solve the problem.

How do you check if a zip file is corrupted in Java?

Your code is basically OK, try to find out which file is responsible for the corrupted zip file. Check whether digitalFile. getFile() always returns a valid and accessible argument to FileInputStream. Just add a bit logging to your code and you will find out what's wrong.


2 Answers

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)
like image 54
AzizSM Avatar answered Sep 18 '22 12:09

AzizSM


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.

like image 20
Cheeso Avatar answered Sep 21 '22 12:09

Cheeso