Is there a method to detect for zip compression? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Is there a method to detect for zip compression?

Post by tbreina »

I'm able to use the wxZipInputStream to correctly unzip files from my program.

Is there a way to have wxZipInputStream (or something similar) detect whether a file is actually zipped (without having to peek at the .zip extension)? For example, should I be looking for GetNextEntry to be NULL when the file is first opened? Or, is there a preferred way?

Thanks.
-Tony
Everybody's got something to hide except for me and my monkey.
Jophin
Knows some wx things
Knows some wx things
Posts: 41
Joined: Sun Apr 05, 2009 1:53 am
Location: Maharashtra , India

Post by Jophin »

The first two bytes of zip file has characters 'PK' ( i.e. 0x50,0x4B ) ; as this format was originally created in 1986 by Phil Katz for PKZIP

Use the two signature bytes to detect zip compressed files.

Just for knowledge wiki comparison of file archivers @ http://en.wikipedia.org/wiki/List_of_fi ... at_support
Jophin K.
Maharashtra , India
tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Post by tbreina »

Jophin wrote:The first two bytes of zip file has characters 'PK' ( i.e. 0x50,0x4B ) ; as this format was originally created in 1986 by Phil Katz for PKZIP

Use the two signature bytes to detect zip compressed files.

Just for knowledge wiki comparison of file archivers @ http://en.wikipedia.org/wiki/List_of_fi ... at_support
That's a good solution, but I was wondering if there was a more generic one. For example, if I used wxTarInputStream or wxBZipInputStream, then I would need to find similar signature bytes for those archive/compression formats.

I was hoping there was some sort of error flag for these wxArchiveEntry types that would tell me that the file couldn't be opened with that data type (and I could assume that the file wasn't in that format). Maybe wxFileSystem would work with an archive file handler??

-Tony
Everybody's got something to hide except for me and my monkey.
Jophin
Knows some wx things
Knows some wx things
Posts: 41
Joined: Sun Apr 05, 2009 1:53 am
Location: Maharashtra , India

Post by Jophin »

Found a site containing all the files signature bytes http://www.garykessler.net/library/file_sigs.html

Hope this will help you...... :lol:

For error flag's I presume all files depends upon their CRC check.

"Happy Diwali To EveryOne"
Last edited by Jophin on Sat Oct 17, 2009 2:21 am, edited 1 time in total.
Jophin K.
Maharashtra , India
tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Post by tbreina »

Jophin wrote:Found a site containing all the files signature bytes http://www.garykessler.net/library/file_sigs.html

Hope this will help you...... :lol:

"Happy Diwali To EveryOne"
Thanks.

One more question: Do I have to take endianess into account here if I read the file signature bytes?

-Tony
Everybody's got something to hide except for me and my monkey.
Jophin
Knows some wx things
Knows some wx things
Posts: 41
Joined: Sun Apr 05, 2009 1:53 am
Location: Maharashtra , India

Post by Jophin »

For endianess or byte-order , Probably Yes! it should be taken in account.

For example if you compare signature for TIFF file in http://www.garykessler.net/library/file_sigs.html you will see '0x49,0x49' for Intel, or little endian and 0x4D,0x4D for Motorola, or big endian.
Jophin K.
Maharashtra , India
Post Reply