For Programmers: Free Programming Magazines  


Home > Archive > Compression > November 2004 > renaming files in a zip archive without uncompressing?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author renaming files in a zip archive without uncompressing?
William Krick

2004-11-27, 8:55 am

I'm trying to write a (Win32) command line utility that can rename
files within a zip archive without decompressing or recompressing the
contents. I'd like to use zlib.

I'm not particularly familiar with the ins and outs of zlib or even
how the names are stored within the zip archive. But before I begin,
I'd like to know if this something that be done easily or at all?

any thoughts, tips, or links to sample code would be appreciated

thanks
....
Krick
Mike B

2004-11-27, 8:55 am

Hi William

ZLib is a compression library and not a zip archive support library, so
while it will easily handle the actual compression of data, you will have to
add your own code to manipulate zip files.

The ZLib distribution contains some 3rd Party source code, some of which do
support zip files.

However, if all you are interested in doing is renaming files within the zip
archive, then you do not need ZLib as you will not need to compress any
data.

You might want to look at other options as there is plenty of freely
available source code to do this. Just do a web search.

regards
Mike

"William Krick" <wkrick@gmail.com> wrote in message
news:c08557e4.0411270015.62eade37@posting.google.com...
> I'm trying to write a (Win32) command line utility that can rename
> files within a zip archive without decompressing or recompressing the
> contents. I'd like to use zlib.
>
> I'm not particularly familiar with the ins and outs of zlib or even
> how the names are stored within the zip archive. But before I begin,
> I'd like to know if this something that be done easily or at all?
>
> any thoughts, tips, or links to sample code would be appreciated
>
> thanks
> ...
> Krick



Mark Adler

2004-11-27, 3:55 pm

wkrick@gmail.com (William Krick) wrote in message news:<c08557e4.0411270015.62eade37@posting.google.com>...
> I'm trying to write a (Win32) command line utility that can rename
> files within a zip archive without decompressing or recompressing the
> contents. I'd like to use zlib.


All that zlib can do for you is uncompress and compress. So you will
have succeeded in your objective if you make no use of zlib
whatsoever!

It should be relatively straightforward to modify the filenames in a
zip file, while changing nothing else, at least if the central
directory isn't encrypted. The only part that will require some care
is updating the relative offsets of the local headers in the central
headers, since the new filenames will in general be a different length
than the old filenames. Those offsets may be in a zip64 extra field
for large zip files. Also it's not trivial to find the central
directory without decompressing entries in the somewhat broken zip
file format, but it can be done (see Info-ZIP's unzip).

What you need to do is get the appnote from pkware.com which has the
latest description of the zipfile format.

mark
William Krick

2004-11-30, 8:55 pm

madler@alumni.caltech.edu (Mark Adler) wrote in message news:<7ab39013.0411270745.2056fca9@posting.google.com>...
> wkrick@gmail.com (William Krick) wrote in message news:<c08557e4.0411270015.62eade37@posting.google.com>...
>
> It should be relatively straightforward to modify the filenames in a
> zip file, while changing nothing else, at least if the central
> directory isn't encrypted. The only part that will require some care
> is updating the relative offsets of the local headers in the central
> headers, since the new filenames will in general be a different length
> than the old filenames. Those offsets may be in a zip64 extra field
> for large zip files. Also it's not trivial to find the central
> directory without decompressing entries in the somewhat broken zip
> file format, but it can be done (see Info-ZIP's unzip).
>
> What you need to do is get the appnote from pkware.com which has the
> latest description of the zipfile format.
>
> mark


Fortunately, I only need to support PKZip 2.04g compatible zip files
(deflate only) so I can safely ignore the "extensions" to the zip
format. I don't need to support encrypted files or anything like that
either.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com