Is this file a compressed zip file ?

Hi all,My program receive a file, which can be a regular file or a compressed zip file ...Is there any way for it to determine if this file is a zip one in order to decompress it ?Thanks !Vincent
[237 byte] By [ Vince] at [2007-9-30 9:07:48]
# 1
How are you receiving the file? If you are using HTTP/servlets, you can inspect the content-encoding header. If you are using a custom format, send the type before the file.- Saish"My karma ran over your dogma." - Anon
Saish at 2007-7-2 21:36:39 > top of Java-index,Administration Tools,Sun Connection...
# 2

Try to handle it as a zip file (including maybe the perusal of its contents) and see whether there is an error.

Some platforms come however with the command called "file" which guesses the file type basically upon its contents.

$ file a.xls a.doc c.c bubu.ppt

a.xls:ISO-8859 Java program text

a.doc:ASCII text, with very long lines, with CRLF, LF line terminators

c.c:empty

bubu.ppt: Zip archive data, at least v1.0 to extract

NAME

file - determine file type

SYNOPSIS

file [ -bciknsvzL ] [ -f namefile ] [ -m magicfiles ] file ...

file -C [ -m magicfile ]

HISTORY

There has been a file command in every UNIX since at least Research Version 6 (man page dated January 16, 1975). The System V version introduced one significant major change: the external list of magic number types. This slowed the program down slightly but made it a lot more flexible.

BIJ at 2007-7-2 21:36:39 > top of Java-index,Administration Tools,Sun Connection...