I use the "diff" command to compare two compressed files generated using zip on the exact same starting file and they are reported as being different. However, when I uncompress them and use the "diff" command, no differences are shown. I've noticed this with both zip and gzip.

link|improve this question

feedback

3 Answers

up vote 2 down vote accepted

You might also like to use zdiff if you do want to compare the compressed contents.

link|improve this answer
feedback

One of the fields in the gzip header is different between the two files. One such field is the last modified time of the compressed file (in seconds since 1970), or if the compressed data was not read from a file, then the time when the file was compressed.

Even a one second difference is enough to make the gzip files not match.

link|improve this answer
Thanks for more specifics! – molecules Dec 18 '09 at 20:59
feedback

Two possible causes:

  • different compression algorithm used by the same compression program, or
  • different compression programs
link|improve this answer
2  
I didn't think to add that the PKZip file spec, for example, includes data areas that are reserved for comments. It may be that gzip (etc) may be putting data in the comment locations that include values like the Date and Time, which would cause the binary differences you're seeing. They wouldn't affect the data that is compressed, just the final compressed archive. – JMD Dec 18 '09 at 20:41
Thanks. I did not think to mention that they were generated by the same program with the same command line options. I did not change any parameters when zipping the two files. +1 when I can. – molecules Dec 18 '09 at 20:42
+1 That totally makes sense. Thanks! – molecules Dec 18 '09 at 20:43
Sorry. I really needed zdiff, but didn't realize that I should have asked for it. – molecules Dec 18 '09 at 22:12
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.