547 lines
17 KiB
HTML
547 lines
17 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Archive::Zip::FAQ</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Archive::Zip::FAQ</H1>
|
|
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2020-02-27<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Archive::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip
|
|
<A NAME="lbAC"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
It seems that I keep answering the same questions over and over again. I
|
|
assume that this is because my documentation is deficient, rather than that
|
|
people don't read the documentation.
|
|
<P>
|
|
|
|
So this <FONT SIZE="-1">FAQ</FONT> is an attempt to cut down on the number of personal answers I have
|
|
to give. At least I can now say "You <I>did</I> read the <FONT SIZE="-1">FAQ,</FONT> right?".
|
|
<P>
|
|
|
|
The questions are not in any particular order. The answers assume the current
|
|
version of Archive::Zip; some of the answers depend on newly added/fixed
|
|
functionality.
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Install problems on RedHat 8 or 9 with Perl 5.8.0</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Archive::Zip won't install on my RedHat 9 system! It's broke!
|
|
<P>
|
|
|
|
<B>A:</B> This has become something of a <FONT SIZE="-1">FAQ.</FONT>
|
|
Basically, RedHat broke some versions of Perl by setting <FONT SIZE="-1">LANG</FONT> to <FONT SIZE="-1">UTF8.</FONT>
|
|
They apparently have a fixed version out as an update.
|
|
<P>
|
|
|
|
You might try running <FONT SIZE="-1">CPAN</FONT> or creating your Makefile after exporting the <FONT SIZE="-1">LANG</FONT>
|
|
environment variable as
|
|
<P>
|
|
|
|
<TT>"LANG=C"</TT>
|
|
<P>
|
|
|
|
<<A HREF="https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=87682">https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=87682</A>>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>Why is my zip file so big?</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> My zip file is actually bigger than what I stored in it! Why?
|
|
<P>
|
|
|
|
<B>A:</B> Some things to make sure of:
|
|
<DL COMPACT>
|
|
<DT id="1">Make sure that you are requesting <FONT SIZE="-1">COMPRESSION_DEFLATED</FONT> if you are storing strings.<DD>
|
|
|
|
|
|
<TT>$member</TT>->desiredCompressionMethod( <FONT SIZE="-1">COMPRESSION_DEFLATED</FONT> );
|
|
<DT id="2">Don't make lots of little files if you can help it.<DD>
|
|
|
|
|
|
Since zip computes the compression tables for each member, small
|
|
members without much entropy won't compress well. Instead, if you've
|
|
got lots of repeated strings in your data, try to combine them into
|
|
one big member.
|
|
<DT id="3">Make sure that you are requesting <FONT SIZE="-1">COMPRESSION_STORED</FONT> if you are storing things that are already compressed.<DD>
|
|
|
|
|
|
If you're storing a .zip, .jpg, .mp3, or other compressed file in a zip,
|
|
then don't compress them again. They'll get bigger.
|
|
</DL>
|
|
<A NAME="lbAF"> </A>
|
|
<H2>Sample code?</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Can you send me code to do (whatever)?
|
|
<P>
|
|
|
|
<B>A:</B> Have you looked in the <TT>"examples/"</TT> directory yet? It contains:
|
|
<DL COMPACT>
|
|
<DT id="4">examples/calcSizes.pl --- How to find out how big a Zip file will be before writing it<DD>
|
|
|
|
|
|
|
|
<DT id="5">examples/copy.pl --- Copies one Zip file to another<DD>
|
|
|
|
|
|
<DT id="6">examples/extract.pl --- extract file(s) from a Zip<DD>
|
|
|
|
|
|
<DT id="7">examples/mailZip.pl --- make and mail a zip file<DD>
|
|
|
|
|
|
<DT id="8">examples/mfh.pl --- demo for use of MockFileHandle<DD>
|
|
|
|
|
|
<DT id="9">examples/readScalar.pl --- shows how to use IO::Scalar as the source of a Zip read<DD>
|
|
|
|
|
|
<DT id="10">examples/selfex.pl --- a brief example of a self-extracting Zip<DD>
|
|
|
|
|
|
<DT id="11">examples/unzipAll.pl --- uses Archive::Zip::Tree to unzip an entire Zip<DD>
|
|
|
|
|
|
<DT id="12">examples/updateZip.pl --- shows how to read/modify/write a Zip<DD>
|
|
|
|
|
|
<DT id="13">examples/updateTree.pl --- shows how to update a Zip in place<DD>
|
|
|
|
|
|
<DT id="14">examples/writeScalar.pl --- shows how to use IO::Scalar as the destination of a Zip write<DD>
|
|
|
|
|
|
<DT id="15">examples/writeScalar2.pl --- shows how to use IO::String as the destination of a Zip write<DD>
|
|
|
|
|
|
<DT id="16">examples/zip.pl --- Constructs a Zip file<DD>
|
|
|
|
|
|
<DT id="17">examples/zipcheck.pl --- One way to check a Zip file for validity<DD>
|
|
|
|
|
|
<DT id="18">examples/zipinfo.pl --- Prints out information about a Zip archive file<DD>
|
|
|
|
|
|
<DT id="19">examples/zipGrep.pl --- Searches for text in Zip files<DD>
|
|
|
|
|
|
<DT id="20">examples/ziptest.pl --- Lists a Zip file and checks member CRCs<DD>
|
|
|
|
|
|
<DT id="21">examples/ziprecent.pl --- Puts recent files into a zipfile<DD>
|
|
|
|
|
|
<DT id="22">examples/ziptest.pl --- Another way to check a Zip file for validity<DD>
|
|
|
|
|
|
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>Can't Read/modify/write same Zip file</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Why can't I open a Zip file, add a member, and write it back? I get an
|
|
error message when I try.
|
|
<P>
|
|
|
|
<B>A:</B> Because Archive::Zip doesn't (and can't, generally) read file contents into memory,
|
|
the original Zip file is required to stay around until the writing of the new
|
|
file is completed.
|
|
<P>
|
|
|
|
The best way to do this is to write the Zip to a temporary file and then
|
|
rename the temporary file to have the old name (possibly after deleting the
|
|
old one).
|
|
<P>
|
|
|
|
Archive::Zip v1.02 added the archive methods <TT>"overwrite()"</TT> and
|
|
<TT>"overwriteAs()"</TT> to do this simply and carefully.
|
|
<P>
|
|
|
|
See <TT>"examples/updateZip.pl"</TT> for an example of this technique.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>File creation time not set</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Upon extracting files, I see that their modification (and access) times are
|
|
set to the time in the Zip archive. However, their creation time is not set to
|
|
the same time. Why?
|
|
<P>
|
|
|
|
<B>A:</B> Mostly because Perl doesn't give cross-platform access to <I>creation time</I>.
|
|
Indeed, many systems (like Unix) don't support such a concept.
|
|
However, if yours does, you can easily set it. Get the modification time from
|
|
the member using <TT>"lastModTime()"</TT>.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>Can't use Archive::Zip on gzip files</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Can I use Archive::Zip to extract Unix gzip files?
|
|
<P>
|
|
|
|
<B>A:</B> No.
|
|
<P>
|
|
|
|
There is a distinction between Unix gzip files, and Zip archives that
|
|
also can use the gzip compression.
|
|
<P>
|
|
|
|
Depending on the format of the gzip file, you can use Compress::Raw::Zlib, or
|
|
Archive::Tar to decompress it (and de-archive it in the case of Tar files).
|
|
<P>
|
|
|
|
You can unzip PKZIP/WinZip/etc/ archives using Archive::Zip (that's what
|
|
it's for) as long as any compressed members are compressed using
|
|
Deflate compression.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>Add a directory/tree to a Zip</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How can I add a directory (or tree) full of files to a Zip?
|
|
<P>
|
|
|
|
<B>A:</B> You can use the Archive::Zip::addTree*() methods:
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
use Archive::Zip;
|
|
my $zip = Archive::Zip->new();
|
|
# add all readable files and directories below . as xyz/*
|
|
$zip->addTree( '.', 'xyz' );
|
|
# add all readable plain files below /abc as def/*
|
|
$zip->addTree( '/abc', 'def', sub { -f && -r } );
|
|
# add all .c files below /tmp as stuff/*
|
|
$zip->addTreeMatching( '/tmp', 'stuff', '\.c$' );
|
|
# add all .o files below /tmp as stuff/* if they aren't writable
|
|
$zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { ! -w } );
|
|
# add all .so files below /tmp that are smaller than 200 bytes as stuff/*
|
|
$zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { -s < 200 } );
|
|
# and write them into a file
|
|
$zip->writeToFileNamed('xxx.zip');
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>Extract a directory/tree</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How can I extract some (or all) files from a Zip into a different
|
|
directory?
|
|
<P>
|
|
|
|
<B>A:</B> You can use the <B>Archive::Zip::extractTree()</B> method:
|
|
??? ||
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
# now extract the same files into /tmpx
|
|
$zip->extractTree( 'stuff', '/tmpx' );
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>Update a directory/tree</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How can I update a Zip from a directory tree, adding or replacing only
|
|
the newer files?
|
|
<P>
|
|
|
|
<B>A:</B> You can use the <B>Archive::Zip::updateTree()</B> method that was added in version 1.09.
|
|
<A NAME="lbAM"> </A>
|
|
<H2>Zip times might be off by 1 second</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> It bothers me greatly that my file times are wrong by one second about half
|
|
the time. Why don't you do something about it?
|
|
<P>
|
|
|
|
<B>A:</B> Get over it. This is a result of the Zip format storing times in <FONT SIZE="-1">DOS</FONT>
|
|
format, which has a resolution of only two seconds.
|
|
<A NAME="lbAN"> </A>
|
|
<H2>Zip times don't include time zone information</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> My file times don't respect time zones. What gives?
|
|
<P>
|
|
|
|
<B>A:</B> If this is important to you, please submit patches to read the various
|
|
Extra Fields that encode times with time zones. I'm just using the <FONT SIZE="-1">DOS</FONT>
|
|
Date/Time, which doesn't have a time zone.
|
|
<A NAME="lbAO"> </A>
|
|
<H2>How do I make a self-extracting Zip</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> I want to make a self-extracting Zip file. Can I do this?
|
|
<P>
|
|
|
|
<B>A:</B> Yes. You can write a self-extracting archive stub (that is, a version of
|
|
unzip) to the output filehandle that you pass to <B>writeToFileHandle()</B>. See
|
|
examples/selfex.pl for how to write a self-extracting archive.
|
|
<P>
|
|
|
|
However, you should understand that this will only work on one kind of
|
|
platform (the one for which the stub was compiled).
|
|
<A NAME="lbAP"> </A>
|
|
<H2>How can I deal with Zips with prepended garbage (i.e. from Sircam)</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How can I tell if a Zip has been damaged by adding garbage to the
|
|
beginning or inside the file?
|
|
<P>
|
|
|
|
<B>A:</B> I added code for this for the Amavis virus scanner. You can query archives
|
|
for their 'eocdOffset' property, which should be 0:
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
if ($zip->eocdOffset > 0)
|
|
{ warn($zip->eocdOffset . " bytes of garbage at beginning or within Zip") }
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
When members are extracted, this offset will be used to adjust the start of
|
|
the member if necessary.
|
|
<A NAME="lbAQ"> </A>
|
|
<H2>Can't extract Shrunk files</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> I'm trying to extract a file out of a Zip produced by <FONT SIZE="-1">PKZIP,</FONT> and keep
|
|
getting this error message:
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
error: Unsupported compression combination: read 6, write 0
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
<B>A:</B> You can't uncompress this archive member. Archive::Zip only supports uncompressed
|
|
members, and compressed members that are compressed using the compression
|
|
supported by Compress::Raw::Zlib. That means only Deflated and Stored members.
|
|
<P>
|
|
|
|
Your file is compressed using the Shrink format, which is not supported by
|
|
Compress::Raw::Zlib.
|
|
<P>
|
|
|
|
You could, perhaps, use a command-line UnZip program (like the Info-Zip
|
|
one) to extract this.
|
|
<A NAME="lbAR"> </A>
|
|
<H2>Can't do decryption</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How do I decrypt encrypted Zip members?
|
|
<P>
|
|
|
|
<B>A:</B> With some other program or library. Archive::Zip doesn't support decryption,
|
|
and probably never will (unless <I>you</I> write it).
|
|
<A NAME="lbAS"> </A>
|
|
<H2>How to test file integrity?</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How can Archive::Zip can test the validity of a Zip file?
|
|
<P>
|
|
|
|
<B>A:</B> If you try to decompress the file, the gzip streams will report errors
|
|
if you have garbage. Most of the time.
|
|
<P>
|
|
|
|
If you try to open the file and a central directory structure can't be
|
|
found, an error will be reported.
|
|
<P>
|
|
|
|
When a file is being read, if we can't find a proper <FONT SIZE="-1">PK..</FONT> signature in
|
|
the right places we report a format error.
|
|
<P>
|
|
|
|
If there is added garbage at the beginning of a Zip file (as inserted
|
|
by some viruses), you can find out about it, but Archive::Zip will ignore it,
|
|
and you can still use the archive. When it gets written back out the
|
|
added stuff will be gone.
|
|
<P>
|
|
|
|
There are two ready-to-use utilities in the examples directory that can
|
|
be used to test file integrity, or that you can use as examples
|
|
for your own code:
|
|
<DL COMPACT>
|
|
<DT id="23">examples/zipcheck.pl shows how to use an attempted extraction to test a file.<DD>
|
|
|
|
|
|
|
|
<DT id="24">examples/ziptest.pl shows how to test CRCs in a file.<DD>
|
|
|
|
|
|
|
|
</DL>
|
|
<A NAME="lbAT"> </A>
|
|
<H2>Duplicate files in Zip?</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Archive::Zip let me put the same file in my Zip twice! Why don't you prevent this?
|
|
<P>
|
|
|
|
<B>A:</B> As far as I can tell, this is not disallowed by the Zip spec. If you
|
|
think it's a bad idea, check for it yourself:
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
$zip->addFile($someFile, $someName) unless $zip->memberNamed($someName);
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
I can even imagine cases where this might be useful (for instance, multiple
|
|
versions of files).
|
|
<A NAME="lbAU"> </A>
|
|
<H2>File ownership/permissions/ACLS/etc</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> Why doesn't Archive::Zip deal with file ownership, ACLs, etc.?
|
|
<P>
|
|
|
|
<B>A:</B> There is no standard way to represent these in the Zip file format. If
|
|
you want to send me code to properly handle the various extra fields that
|
|
have been used to represent these through the years, I'll look at it.
|
|
<A NAME="lbAV"> </A>
|
|
<H2>I can't compile but ActiveState only has an old version of Archive::Zip</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> I've only installed modules using ActiveState's <FONT SIZE="-1">PPM</FONT> program and
|
|
repository. But they have a much older version of Archive::Zip than is in <FONT SIZE="-1">CPAN.</FONT> Will
|
|
you send me a newer <FONT SIZE="-1">PPM</FONT>?
|
|
<P>
|
|
|
|
<B>A:</B> Probably not, unless I get lots of extra time. But there's no reason you
|
|
can't install the version from <FONT SIZE="-1">CPAN.</FONT> Archive::Zip is pure Perl, so all you need is
|
|
<FONT SIZE="-1">NMAKE,</FONT> which you can get for free from Microsoft (see the <FONT SIZE="-1">FAQ</FONT> in the
|
|
ActiveState documentation for details on how to install <FONT SIZE="-1">CPAN</FONT> modules).
|
|
<A NAME="lbAW"> </A>
|
|
<H2>My JPEGs (or MP3's) don't compress when I put them into Zips!</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How come my JPEGs and <FONT SIZE="-1">MP3</FONT>'s don't compress much when I put them into Zips?
|
|
<P>
|
|
|
|
<B>A:</B> Because they're already compressed.
|
|
<A NAME="lbAX"> </A>
|
|
<H2>Under Windows, things lock up/get damaged</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> I'm using Windows. When I try to use Archive::Zip, my machine locks up/makes
|
|
funny sounds/displays a BSOD/corrupts data. How can I fix this?
|
|
<P>
|
|
|
|
<B>A:</B> First, try the newest version of Compress::Raw::Zlib. I know of
|
|
Windows-related problems prior to v1.14 of that library.
|
|
<A NAME="lbAY"> </A>
|
|
<H2>Zip contents in a scalar</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> I want to read a Zip file from (or write one to) a scalar variable instead
|
|
of a file. How can I do this?
|
|
<P>
|
|
|
|
<B>A:</B> Use <TT>"IO::String"</TT> and the <TT>"readFromFileHandle()"</TT> and
|
|
<TT>"writeToFileHandle()"</TT> methods.
|
|
See <TT>"examples/readScalar.pl"</TT> and <TT>"examples/writeScalar.pl"</TT>.
|
|
<A NAME="lbAZ"> </A>
|
|
<H2>Reading from streams</H2>
|
|
|
|
|
|
|
|
<B>Q:</B> How do I read from a stream (like for the Info-Zip <TT>"funzip"</TT> program)?
|
|
<P>
|
|
|
|
<B>A:</B> This is not currently supported, though writing to a stream is.
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="25"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="26"><A HREF="#lbAC">DESCRIPTION</A><DD>
|
|
<DT id="27"><A HREF="#lbAD">Install problems on RedHat 8 or 9 with Perl 5.8.0</A><DD>
|
|
<DT id="28"><A HREF="#lbAE">Why is my zip file so big?</A><DD>
|
|
<DT id="29"><A HREF="#lbAF">Sample code?</A><DD>
|
|
<DT id="30"><A HREF="#lbAG">Can't Read/modify/write same Zip file</A><DD>
|
|
<DT id="31"><A HREF="#lbAH">File creation time not set</A><DD>
|
|
<DT id="32"><A HREF="#lbAI">Can't use Archive::Zip on gzip files</A><DD>
|
|
<DT id="33"><A HREF="#lbAJ">Add a directory/tree to a Zip</A><DD>
|
|
<DT id="34"><A HREF="#lbAK">Extract a directory/tree</A><DD>
|
|
<DT id="35"><A HREF="#lbAL">Update a directory/tree</A><DD>
|
|
<DT id="36"><A HREF="#lbAM">Zip times might be off by 1 second</A><DD>
|
|
<DT id="37"><A HREF="#lbAN">Zip times don't include time zone information</A><DD>
|
|
<DT id="38"><A HREF="#lbAO">How do I make a self-extracting Zip</A><DD>
|
|
<DT id="39"><A HREF="#lbAP">How can I deal with Zips with prepended garbage (i.e. from Sircam)</A><DD>
|
|
<DT id="40"><A HREF="#lbAQ">Can't extract Shrunk files</A><DD>
|
|
<DT id="41"><A HREF="#lbAR">Can't do decryption</A><DD>
|
|
<DT id="42"><A HREF="#lbAS">How to test file integrity?</A><DD>
|
|
<DT id="43"><A HREF="#lbAT">Duplicate files in Zip?</A><DD>
|
|
<DT id="44"><A HREF="#lbAU">File ownership/permissions/ACLS/etc</A><DD>
|
|
<DT id="45"><A HREF="#lbAV">I can't compile but ActiveState only has an old version of Archive::Zip</A><DD>
|
|
<DT id="46"><A HREF="#lbAW">My JPEGs (or MP3's) don't compress when I put them into Zips!</A><DD>
|
|
<DT id="47"><A HREF="#lbAX">Under Windows, things lock up/get damaged</A><DD>
|
|
<DT id="48"><A HREF="#lbAY">Zip contents in a scalar</A><DD>
|
|
<DT id="49"><A HREF="#lbAZ">Reading from streams</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:35 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|