How can one detect the type of compression used on the file? (assuming that .zip, .gz, .xz or any other extension is not specified).
Is this information stored somewhere in the header of that file?
You can check the extension. If you don't trust the extension, then you have to look into the file and check for signatures. You can find some of them here. The call to stat will not tell you about individual files being compressed, as this flag means that the file system is compressed.
tar file extension is not a type of compressed file, it is actually a single file that contains a group of files that is uncompressed.
Common compressed file extensions are . ZIP, . RAR, . ARJ, .
You can determine that it is likely to be one of those formats by looking at the first few bytes. You should then test to see if it really is one of those, using an integrity check from the associated utility for that format, or by actually proceeding to decompress.
You can find the header formats in the descriptions:
Others:
0xFD2FB528
, a skipable frame starts with 0x184D2A5?
(question mark is any value from 0 to F), and dictionary starts with 0xEC30A437
.file
commandIf you're on a Linux box just use the 'file' command.
http://en.wikipedia.org/wiki/File_(command)
$ mv foo.zip dink $ file dink dink: gzip compressed data, from Unix, last modified: Sat Aug 6 08:08:57 2011, max compression $
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With