Reputation: 9
Given a file, using the magic sequence, I can detect with compression type it belongs to. But magic sequence for gzip and tarGzip is the same. So, how can I differentiate between these 2 file types.
On https://en.wikipedia.org/wiki/List_of_file_signatures , we can see that the file signature for both these files is hexadecimal 1f 8b
Upvotes: 1
Views: 577
Reputation: 112607
Decompress the first 1K bytes and check the tar checksum on the first 512 of those. If that matches, it is very likely you are dealing with a tar file. (If there aren't 1024 bytes, then it isn't a tar file.)
Upvotes: 1