I have found the question How to determine if data is valid tar file without a file?, but I was wondering: is there a ready made command line solution?
These are all very sub-optimal solutions. From the GZIP spec
ID2 (IDentification 2) These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 (0x8b, \213), to identify the file as being in gzip format.
Has to be coded into whatever language you're using.