.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Archive::Zip::FAQ 3" .TH Archive::Zip::FAQ 3 "2009-06-30" "perl v5.8.4" "User Contributed Perl Documentation" .SH "NAME" Archive::Zip::FAQ \- Answers to a few frequently asked questions about Archive::Zip .SH "DESCRIPTION" .IX Header "DESCRIPTION" 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. .PP So this \s-1FAQ\s0 is an attempt to cut down on the number of personal answers I have to give. At least I can now say "You \fIdid\fR read the \s-1FAQ\s0, right?". .PP 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. .SH "Install problems on RedHat 8 or 9 with Perl 5.8.0" .IX Header "Install problems on RedHat 8 or 9 with Perl 5.8.0" \&\fBQ:\fR Archive::Zip won't install on my RedHat 9 system! It's broke! .PP \&\fBA:\fR This has become something of a \s-1FAQ\s0. Basically, RedHat broke some versions of Perl by setting \s-1LANG\s0 to \s-1UTF8\s0. They apparently have a fixed version out as an update. .PP You might try running \s-1CPAN\s0 or creating your Makefile after exporting the \s-1LANG\s0 environment variable as .PP \&\f(CW\*(C`LANG=C\*(C'\fR .PP .SH "Why is my zip file so big?" .IX Header "Why is my zip file so big?" \&\fBQ:\fR My zip file is actually bigger than what I stored in it! Why? .PP \&\fBA:\fR Some things to make sure of: .IP "Make sure that you are requesting \s-1COMPRESSION_DEFLATED\s0 if you are storing strings." 4 .IX Item "Make sure that you are requesting COMPRESSION_DEFLATED if you are storing strings." $member\->desiredCompressionMethod( \s-1COMPRESSION_DEFLATED\s0 ); .IP "Don't make lots of little files if you can help it." 4 .IX Item "Don't make lots of little files if you can help it." 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. .IP "Make sure that you are requesting \s-1COMPRESSION_STORED\s0 if you are storing things that are already compressed." 4 .IX Item "Make sure that you are requesting COMPRESSION_STORED if you are storing things that are already compressed." 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. .SH "Sample code?" .IX Header "Sample code?" \&\fBQ:\fR Can you send me code to do (whatever)? .PP \&\fBA:\fR Have you looked in the \f(CW\*(C`examples/\*(C'\fR directory yet? It contains: .IP "examples/calcSizes.pl \*(-- How to find out how big a Zip file will be before writing it" 4 .IX Item "examples/calcSizes.pl How to find out how big a Zip file will be before writing it" .PD 0 .IP "examples/copy.pl \*(-- Copies one Zip file to another" 4 .IX Item "examples/copy.pl Copies one Zip file to another" .IP "examples/extract.pl \*(-- extract file(s) from a Zip" 4 .IX Item "examples/extract.pl extract file(s) from a Zip" .IP "examples/mailZip.pl \*(-- make and mail a zip file" 4 .IX Item "examples/mailZip.pl make and mail a zip file" .IP "examples/mfh.pl \*(-- demo for use of MockFileHandle" 4 .IX Item "examples/mfh.pl demo for use of MockFileHandle" .IP "examples/readScalar.pl \*(-- shows how to use IO::Scalar as the source of a Zip read" 4 .IX Item "examples/readScalar.pl shows how to use IO::Scalar as the source of a Zip read" .IP "examples/selfex.pl \*(-- a brief example of a self-extracting Zip" 4 .IX Item "examples/selfex.pl a brief example of a self-extracting Zip" .IP "examples/unzipAll.pl \*(-- uses Archive::Zip::Tree to unzip an entire Zip" 4 .IX Item "examples/unzipAll.pl uses Archive::Zip::Tree to unzip an entire Zip" .IP "examples/updateZip.pl \*(-- shows how to read/modify/write a Zip" 4 .IX Item "examples/updateZip.pl shows how to read/modify/write a Zip" .IP "examples/updateTree.pl \*(-- shows how to update a Zip in place" 4 .IX Item "examples/updateTree.pl shows how to update a Zip in place" .IP "examples/writeScalar.pl \*(-- shows how to use IO::Scalar as the destination of a Zip write" 4 .IX Item "examples/writeScalar.pl shows how to use IO::Scalar as the destination of a Zip write" .IP "examples/writeScalar2.pl \*(-- shows how to use IO::String as the destination of a Zip write" 4 .IX Item "examples/writeScalar2.pl shows how to use IO::String as the destination of a Zip write" .IP "examples/zip.pl \*(-- Constructs a Zip file" 4 .IX Item "examples/zip.pl Constructs a Zip file" .IP "examples/zipcheck.pl \*(-- One way to check a Zip file for validity" 4 .IX Item "examples/zipcheck.pl One way to check a Zip file for validity" .IP "examples/zipinfo.pl \*(-- Prints out information about a Zip archive file" 4 .IX Item "examples/zipinfo.pl Prints out information about a Zip archive file" .IP "examples/zipGrep.pl \*(-- Searches for text in Zip files" 4 .IX Item "examples/zipGrep.pl Searches for text in Zip files" .IP "examples/ziptest.pl \*(-- Lists a Zip file and checks member CRCs" 4 .IX Item "examples/ziptest.pl Lists a Zip file and checks member CRCs" .IP "examples/ziprecent.pl \*(-- Puts recent files into a zipfile" 4 .IX Item "examples/ziprecent.pl Puts recent files into a zipfile" .IP "examples/ziptest.pl \*(-- Another way to check a Zip file for validity" 4 .IX Item "examples/ziptest.pl Another way to check a Zip file for validity" .PD .SH "Can't Read/modify/write same Zip file" .IX Header "Can't Read/modify/write same Zip file" \&\fBQ:\fR Why can't I open a Zip file, add a member, and write it back? I get an error message when I try. .PP \&\fBA:\fR 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. .PP 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). .PP Archive::Zip v1.02 added the archive methods \f(CW\*(C`overwrite()\*(C'\fR and \&\f(CW\*(C`overwriteAs()\*(C'\fR to do this simply and carefully. .PP See \f(CW\*(C`examples/updateZip.pl\*(C'\fR for an example of this technique. .SH "File creation time not set" .IX Header "File creation time not set" \&\fBQ:\fR 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? .PP \&\fBA:\fR Mostly because Perl doesn't give cross-platform access to \fIcreation time\fR. 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 \f(CW\*(C`lastModTime()\*(C'\fR. .SH "Can't use Archive::Zip on gzip files" .IX Header "Can't use Archive::Zip on gzip files" \&\fBQ:\fR Can I use Archive::Zip to extract Unix gzip files? .PP \&\fBA:\fR No. .PP There is a distinction between Unix gzip files, and Zip archives that also can use the gzip compression. .PP 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). .PP 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. .SH "Add a directory/tree to a Zip" .IX Header "Add a directory/tree to a Zip" \&\fBQ:\fR How can I add a directory (or tree) full of files to a Zip? .PP \&\fBA:\fR You can use the Archive::Zip::addTree*() methods: .PP .Vb 14 \& 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', '\e.c$' ); \& # add all .o files below /tmp as stuff/* if they aren't writable \& $zip->addTreeMatching( '/tmp', 'stuff', '\e.o$', sub { ! -w } ); \& # add all .so files below /tmp that are smaller than 200 bytes as stuff/* \& $zip->addTreeMatching( '/tmp', 'stuff', '\e.o$', sub { -s < 200 } ); \& # and write them into a file \& $zip->writeToFileNamed('xxx.zip'); .Ve .SH "Extract a directory/tree" .IX Header "Extract a directory/tree" \&\fBQ:\fR How can I extract some (or all) files from a Zip into a different directory? .PP \&\fBA:\fR You can use the \fIArchive::Zip::extractTree()\fR method: ??? || .PP .Vb 2 \& # now extract the same files into /tmpx \& $zip->extractTree( 'stuff', '/tmpx' ); .Ve .SH "Update a directory/tree" .IX Header "Update a directory/tree" \&\fBQ:\fR How can I update a Zip from a directory tree, adding or replacing only the newer files? .PP \&\fBA:\fR You can use the \fIArchive::Zip::updateTree()\fR method that was added in version 1.09. .SH "Zip times might be off by 1 second" .IX Header "Zip times might be off by 1 second" \&\fBQ:\fR 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? .PP \&\fBA:\fR Get over it. This is a result of the Zip format storing times in \s-1DOS\s0 format, which has a resolution of only two seconds. .SH "Zip times don't include time zone information" .IX Header "Zip times don't include time zone information" \&\fBQ:\fR My file times don't respect time zones. What gives? .PP \&\fBA:\fR 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 \s-1DOS\s0 Date/Time, which doesn't have a time zone. .SH "How do I make a self-extracting Zip" .IX Header "How do I make a self-extracting Zip" \&\fBQ:\fR I want to make a self-extracting Zip file. Can I do this? .PP \&\fBA:\fR Yes. You can write a self-extracting archive stub (that is, a version of unzip) to the output filehandle that you pass to \fIwriteToFileHandle()\fR. See examples/selfex.pl for how to write a self-extracting archive. .PP However, you should understand that this will only work on one kind of platform (the one for which the stub was compiled). .SH "How can I deal with Zips with prepended garbage (i.e. from Sircam)" .IX Header "How can I deal with Zips with prepended garbage (i.e. from Sircam)" \&\fBQ:\fR How can I tell if a Zip has been damaged by adding garbage to the beginning or inside the file? .PP \&\fBA:\fR I added code for this for the Amavis virus scanner. You can query archives for their 'eocdOffset' property, which should be 0: .PP .Vb 2 \& if ($zip->eocdOffset > 0) \& { warn($zip->eocdOffset . " bytes of garbage at beginning or within Zip") } .Ve .PP When members are extracted, this offset will be used to adjust the start of the member if necessary. .SH "Can't extract Shrunk files" .IX Header "Can't extract Shrunk files" \&\fBQ:\fR I'm trying to extract a file out of a Zip produced by \s-1PKZIP\s0, and keep getting this error message: .PP .Vb 1 \& error: Unsupported compression combination: read 6, write 0 .Ve .PP \&\fBA:\fR 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. .PP Your file is compressed using the Shrink format, which isn't supported by Compress::Raw::Zlib. .PP You could, perhaps, use a command-line UnZip program (like the Info-Zip one) to extract this. .SH "Can't do decryption" .IX Header "Can't do decryption" \&\fBQ:\fR How do I decrypt encrypted Zip members? .PP \&\fBA:\fR With some other program or library. Archive::Zip doesn't support decryption, and probably never will (unless \fIyou\fR write it). .SH "How to test file integrity?" .IX Header "How to test file integrity?" \&\fBQ:\fR How can Archive::Zip can test the validity of a Zip file? .PP \&\fBA:\fR If you try to decompress the file, the gzip streams will report errors if you have garbage. Most of the time. .PP If you try to open the file and a central directory structure can't be found, an error will be reported. .PP When a file is being read, if we can't find a proper \s-1PK\s0.. signature in the right places we report a format error. .PP 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. .PP 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: .IP "examples/zipcheck.pl shows how to use an attempted extraction to test a file." 4 .IX Item "examples/zipcheck.pl shows how to use an attempted extraction to test a file." .PD 0 .IP "examples/ziptest.pl shows how to test CRCs in a file." 4 .IX Item "examples/ziptest.pl shows how to test CRCs in a file." .PD .SH "Duplicate files in Zip?" .IX Header "Duplicate files in Zip?" \&\fBQ:\fR Archive::Zip let me put the same file in my Zip twice! Why don't you prevent this? .PP \&\fBA:\fR 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: .PP .Vb 1 \& $zip->addFile($someFile, $someName) unless $zip->memberNamed($someName); .Ve .PP I can even imagine cases where this might be useful (for instance, multiple versions of files). .SH "File ownership/permissions/ACLS/etc" .IX Header "File ownership/permissions/ACLS/etc" \&\fBQ:\fR Why doesn't Archive::Zip deal with file ownership, ACLs, etc.? .PP \&\fBA:\fR 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. .SH "I can't compile but ActiveState only has an old version of Archive::Zip" .IX Header "I can't compile but ActiveState only has an old version of Archive::Zip" \&\fBQ:\fR I've only installed modules using ActiveState's \s-1PPM\s0 program and repository. But they have a much older version of Archive::Zip than is in \s-1CPAN\s0. Will you send me a newer \s-1PPM\s0? .PP \&\fBA:\fR Probably not, unless I get lots of extra time. But there's no reason you can't install the version from \s-1CPAN\s0. Archive::Zip is pure Perl, so all you need is \&\s-1NMAKE\s0, which you can get for free from Microsoft (see the \s-1FAQ\s0 in the ActiveState documentation for details on how to install \s-1CPAN\s0 modules). .SH "My JPEGs (or MP3's) don't compress when I put them into Zips!" .IX Header "My JPEGs (or MP3's) don't compress when I put them into Zips!" \&\fBQ:\fR How come my JPEGs and \s-1MP3\s0's don't compress much when I put them into Zips? .PP \&\fBA:\fR Because they're already compressed. .SH "Under Windows, things lock up/get damaged" .IX Header "Under Windows, things lock up/get damaged" \&\fBQ:\fR 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? .PP \&\fBA:\fR First, try the newest version of Compress::Raw::Zlib. I know of Windows-related problems prior to v1.14 of that library. .PP If that doesn't get rid of the problem, fix your computer or get rid of Windows. .SH "Zip contents in a scalar" .IX Header "Zip contents in a scalar" \&\fBQ:\fR I want to read a Zip file from (or write one to) a scalar variable instead of a file. How can I do this? .PP \&\fBA:\fR Use \f(CW\*(C`IO::String\*(C'\fR and the \f(CW\*(C`readFromFileHandle()\*(C'\fR and \&\f(CW\*(C`writeToFileHandle()\*(C'\fR methods. See \f(CW\*(C`examples/readScalar.pl\*(C'\fR and \f(CW\*(C`examples/writeScalar.pl\*(C'\fR. .SH "Reading from streams" .IX Header "Reading from streams" \&\fBQ:\fR How do I read from a stream (like for the Info-Zip \f(CW\*(C`funzip\*(C'\fR program)? .PP \&\fBA:\fR This isn't currently supported, though writing to a stream is.