Re: code to list contents of zip files

Glynn Clements <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Prasanta Sadhukhan wrote:

> I tried to rectify the flaw and now I am getting the whole file contents 
> from the zip file, ie., it is outputting the contents of the file stored 
> in the zipfile.
> But Actually, I wanted only to list the content of the zip file as 
> zipinfo does.

In which case, rather than inflating the data, just skip the number of
bytes indicated by the compressed size field (LOCSIZ), and you should
find a data descriptor, then another header (not necessarily another
local file header; the last file will be followed by a central
directory header).

But for listing, you're probably better off just listing the central
directory, which is found at the end of the file.

This will work even if there is other data at the beginning of the
file (e.g. self-extracting EXEs have the EXE portion at the beginning
of the file and the ZIP data at the end).

I found the unzip source code to be rather messy, due to all of the
platform-specific sections. You might be better off referring to the
format specification at:

http://www.pkware.com/documents/casestudies/APPNOTE.TXT

-- 
Glynn Clements <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.