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 somew
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:
If 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
$
As an alternative to inspecting the file header by hand, you could use some utility like TrID. The link points to the cross-platform command line version; for Windows there's a GUI, too.