Mail Archives: djgpp/1995/11/13/09:57:57
Zippers and unzippers (which include the Gnu programs GZIP and GUNZIP) must
be compatible with PKZIP and PKUNZIP. A manual that came with PKZIP said that
the format of a zip file is as below. This query arose while I was writing a
Gnu C++ program that must poke about in the insides of .zip files.
(1) The `tailend' contains the two fields `us nentries pk; us nfiles pk;',
i.e. one field for `how many entries', and another field for `how many files'.
Are these two fields ever going to be different? If so, how do I tell when an
entry is not a file, and if it is not a file, what will be in it and how to
unpack it?
(2) It said if(centralheader.compmethod==0) if(centralheader.extattr&1)
that entry is an MSDOS directory. But I looked inside a .zip file (one of the
djgpp .zips) which unpacked into trees of files and subdirectories, and in it
I found nothing but files. Is a .zip file ever going to contain a compressed
directory? Or is that a relic of the past? Is there any way that the .zip file
can tell the unzipper to create an empty directory?
header, filename, blah, compressed file that is file 1
header, filename, blah, compressed file that is file 2
etc etc
centralheader, filename, blah, comment for file 1
centralheader, filename, blah, comment for file 2
etc etc
tailend
(and sometimes the file sizes and the CRC are after the compressed file)
where header & centralheader & tailend are as defined below:-
#define pk __attribute__((packed))
#define uns unsigned
typedef uns long ul;
typedef uns short us;
typedef uns char byte;
/*-----*/
class header{public: ul signature pk; byte versionreqd pk; byte opsystem pk;
us gp pk; us compmethod pk; FCBtime time pk; FCBdate date pk; ul crc32 pk;
ul compsize pk; ul uncompsize pk; us fnleng pk; us extraleng pk;};
class centralheader{public: ul signature pk; byte version pk; byte opsystem pk;
byte versionreqd pk; byte opsystemreqd pk; us gp pk; us compmethod pk;
FCBtime time pk; FCBdate date pk; ul crc32 pk; ul compsize pk;
ul uncompsize pk; us fnleng pk; us extraleng pk; us fcommleng pk;
us filediskno pk; us intattr pk; ul extattr pk; ul localoffset pk;};
class tailend{public: ul signature pk; us thisdiskno pk; us cendirbegdiskno pk;
us nentries pk; us nfiles pk; ul cendirsize pk; ul cendiroffset pk;
us commentsize pk;};
- Raw text -