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:

> Is it possible to output the content of a particular file from a zip file?
> For example, in the attached ziptest.c I want to get the contents of a 
> particular file Class3.class from testclasses.zip into a buffer, can 
> anyone point out what I need to change in the code?

Iterate over the files until you find the right one. Either start by
locating the first local file header, then each subsequent one, or
locate the central directory and iterate over the file headers which
are stored there.

For the first method, given the offset of one local file header, the
next one should be located 30 + "file name length" + "extra field length"
+ "compressed size" + 12 bytes further on.

For the second method, the offset from one entry to the next is
46 + "file name length" + "extra field length" + "file comment length".

The start of the central directory can be found from the end of
central directory record, which is at the end of the file. The length
is variable, so you have to scan backwards for the signature (50 4b 05
06), then verify that the offset is 22 + "ZIP file comment length"
bytes before the end of the file).

-- 
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.