Test Multiple Zip Archive Files on macOS

Zip has now become an industry norm for a reason. It’s old enough to be widely available, and it’s old enough to be run on any device without hiccups. But this also means any Zip files could be compressed with substandard softwares and/or distributed through routes that simply cannot guarantee any integrity.

And Mac does NOT escape from this trend of declining quality. Recently I had to update one of my posts covering one of the hidden features in Archive Utility, because of the lackluster updates so far. So how do we remedy this problem? It’s quite simple. First, start using a proper up-to-date compression softwares. Second, test all of your Zip with the following methods.

  1. Open the Terminal.
  2. Replace the bracketed part with the path to a directory and run the following code.
    find [path]  -type f -iname '*.zip' -exec unzip -tq {} \; > diagnostics.txt
  3. Now we are going to forward only the error messages from the log to find faulty files, so simply run the following code.
    grep -v "No errors detected" diagnostics.txt > errors.txt
  4. (optional) If you are looking for a simple list of faulty files, run the following codes.
    grep -e "At least one error" -e "cannot find zipfile directory" errors.txt > errors-list.txt
  5. These text files are going to be located in your home folder.

The log files are in txt format, UTF-8. If you are having problems opening the files with correct encoding, simply open it with Firefox and set the Text Encoding to UTF-8. The chopped up characters, say on Text Edit, is caused by the different normalization methods, which Mac happens not to use. You can read more about it by searching for Unicode equivalence.

Note that not all files flagged as error-ridden will produce an error when decompressed. Both this method and the GUI utility relies on the unzip command from the same package, which was originally released in 1989. It is why the GUI utility and even the command itself is literally a can of worms. Unzip was originally released for classic Mac and Linux, it then later ported on OS X, creating another incompatibility between the standards. This is why simply switching the default encoding on Text Edit cannot display properly; Text Edit is displaying the contents with UTF-8, but with different normalization. While I would call for a new software suite, this method still works if the sole purpose it to test Zip files; however, remember that there will always be false-positives.

Leave a comment