home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _a5653da13bd85ce80b7ebdad2c17b655 < prev    next >
Text File  |  2004-06-01  |  11KB  |  389 lines

  1.  
  2. =head1 NAME
  3.  
  4.  
  5. Archive::Zip FAQ - Answers to a few frequently asked questions about
  6. Archive::Zip
  7.  
  8. =head1 DESCRIPTION
  9.  
  10.  
  11. It seems that I keep answering the same questions over and over again. I
  12. assume that this is because my documentation is deficient, rather than that
  13. people don't read the documentation.
  14.  
  15.  
  16. So this FAQ is an attempt to cut down on the number of personal answers I have
  17. to give. At least I can now say "You I<did> read the FAQ, right?".
  18.  
  19.  
  20. The questions are not in any particular order. The answers assume the current
  21. version of Archive::Zip; some of the answers depend on newly added/fixed
  22. functionality.
  23.  
  24. =head1 Sample code?
  25.  
  26.  
  27. B<Q:> Can you send me code to do (whatever)?
  28.  
  29.  
  30. B<A:> Have you looked in the C<examples/> directory yet? It contains:
  31.  
  32. =over 4
  33.  
  34. =item examples/calcSizes.pl -- How to find out how big a Zip file will be before writing it
  35.  
  36.  
  37.  
  38. =item examples/copy.pl -- Copies one Zip file to another
  39.  
  40.  
  41.  
  42. =item examples/extract.pl -- extract file(s) from a Zip
  43.  
  44.  
  45.  
  46. =item examples/mfh.pl -- demo for use of MockFileHandle
  47.  
  48.  
  49.  
  50. =item examples/readScalar.pl -- shows how to use IO::Scalar as the source of a Zip read
  51.  
  52.  
  53.  
  54. =item examples/selfex.pl -- a brief example of a self-extracting Zip
  55.  
  56.  
  57.  
  58. =item examples/unzipAll.pl -- uses tree operations to unzip an entire Zip
  59.  
  60.  
  61.  
  62. =item examples/updateZip.pl -- shows how to read/modify/write a Zip
  63.  
  64.  
  65.  
  66. =item examples/writeScalar.pl -- shows how to use IO::Scalar as the destination of a Zip write
  67.  
  68.  
  69.  
  70. =item examples/zip.pl -- Constructs a Zip file
  71.  
  72.  
  73.  
  74. =item examples/zipcheck.pl -- One way to check a Zip file for validity
  75.  
  76.  
  77.  
  78. =item examples/zipinfo.pl -- Prints out information about a Zip archive file
  79.  
  80.  
  81.  
  82. =item examples/zipGrep.pl -- Searches for text in Zip files
  83.  
  84.  
  85.  
  86. =item examples/ziptest.pl -- Lists a Zip file and checks member CRCs
  87.  
  88.  
  89.  
  90. =item examples/ziprecent.pl -- Puts recent files into a zipfile
  91.  
  92.  
  93.  
  94. =item examples/ziptest.pl -- Another way to check a Zip file for validity
  95.  
  96.  
  97.  
  98. =back
  99.  
  100. =head1 Can't Read/modify/write same Zip file
  101.  
  102.  
  103. B<Q:> Why can't I open a Zip file, add a member, and write it back? I get an
  104. error message when I try.
  105.  
  106.  
  107. B<A:> Because Archive::Zip doesn't (and can't, generally) read file contents into memory,
  108. the original Zip file is required to stay around until the writing of the new
  109. file is completed.
  110.  
  111.  
  112. The best way to do this is to write the Zip to a temporary file and then
  113. rename the temporary file to have the old name (possibly after deleting the
  114. old one).
  115.  
  116.  
  117. Archive::Zip v1.02 added the archive methods overwrite() and overwriteAs() to
  118. do this simply and carefully.
  119.  
  120.  
  121. See C<examples/updateZip.pl> for an example of this technique.
  122.  
  123. =head1 File creation time not set
  124.  
  125.  
  126. B<Q:> Upon extracting files, I see that their modification (and access) times are
  127. set to the time in the Zip archive. However, their creation time is not set to
  128. the same time. Why?
  129.  
  130.  
  131. B<A:> Mostly because Perl doesn't give cross-platform access to I<creation time>.
  132. Indeed, many systems don't support such a concept.
  133. However, if yours does, you can easily set it. Get the modification time from
  134. the member using C<lastModTime()>.
  135.  
  136. =head1 Can't use Archive::Zip on gzip files
  137.  
  138.  
  139. B<Q:> Can I use Archive::Zip to extract Unix gzip files?
  140.  
  141.  
  142. B<A:> No.
  143.  
  144.  
  145. There is a distinction between Unix gzip files, and Zip archives that 
  146. also can use the gzip compression.
  147.  
  148.  
  149. Depending on the format of the gzip file, you can use Compress::Zlib, or
  150. Archive::Tar to decompress it (and de-archive it in the case of Tar files).
  151.  
  152.  
  153. You can unzip PKZIP/WinZip/etc/ archives using Archive::Zip (that's what 
  154. it's for) as long as any compressed members are compressed using 
  155. Deflate compression.
  156.  
  157. =head1 Add a directory/tree to a Zip
  158.  
  159.  
  160. B<Q:> How can I add a directory (or tree) full of files to a Zip?
  161.  
  162.  
  163. B<A:> You can use the Archive::Zip::addTree*() methods:
  164.  
  165.    use Archive::Zip;
  166.    my $zip = Archive::Zip->new();
  167.    # add all readable files and directories below . as xyz/*
  168.    $zip->addTree( '.', 'xyz' );    
  169.    # add all readable plain files below /abc as def/*
  170.    $zip->addTree( '/abc', 'def', sub { -f && -r } );    
  171.    # add all .c files below /tmp as stuff/*
  172.    $zip->addTreeMatching( '/tmp', 'stuff', '\.c$' );
  173.    # add all .o files below /tmp as stuff/* if they aren't writable
  174.    $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { ! -w } );
  175.    # add all .so files below /tmp that are smaller than 200 bytes as stuff/*
  176.    $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { -s < 200 } );
  177.    # and write them into a file
  178.    $zip->writeToFileNamed('xxx.zip');
  179.  
  180. =head1 Extract a directory/tree
  181.  
  182.  
  183. B<Q:> How can I extract some (or all) files from a Zip into a different
  184. directory?
  185.  
  186.  
  187. B<A:> You can use the Archive::Zip::extractTree() method:
  188. ??? ||
  189.  
  190.  
  191.    # now extract the same files into /tmpx
  192.    $zip->extractTree( 'stuff', '/tmpx' );
  193.  
  194. =head1 Zip times might be off by 1 second
  195.  
  196.  
  197. B<Q:> It bothers me greatly that my file times are wrong by one second about half
  198. the time. Why don't you do something about it?
  199.  
  200.  
  201. B<A:> Get over it. This is a result of the Zip format storing times in DOS
  202. format, which has a resolution of only two seconds.
  203.  
  204. =head1 Zip times don't include time zone information
  205.  
  206.  
  207. B<Q:> My file times don't respect time zones. What gives?
  208.  
  209.  
  210. B<A:> If this is important to you, please submit patches to read the various
  211. Extra Fields that encode times with time zones. I'm just using the DOS
  212. Date/Time, which doesn't have a time zone.
  213.  
  214. =head1 How do I make a self-extracting Zip
  215.  
  216.  
  217. B<Q:> I want to make a self-extracting Zip file. Can I do this?
  218.  
  219.  
  220. B<A:> Yes. You can write a self-extracting archive stub (that is, a version of
  221. unzip) to the output filehandle that you pass to writeToFileHandle(). See
  222. examples/selfex.pl for how to write a self-extracting archive.
  223.  
  224.  
  225. However, you should understand that this will only work on one kind of
  226. platform (the one for which the stub was compiled).
  227.  
  228. =head1 How can I deal with Zips with prepended garbage (i.e. from Sircam)
  229.  
  230.  
  231. B<Q:> How can I tell if a Zip has been damaged by adding garbage to the
  232. beginning?
  233.  
  234.  
  235. B<A:> I added code for this for the Amavis virus scanner. You can query archives
  236. for their 'eocdOffset' property, which should be 0:
  237.  
  238.  
  239.   if ($zip->eocdOffset > 0)
  240.     { warn($zip->eocdOffset . " bytes of garbage at beginning of Zip") }
  241.  
  242. =head1 Can't extract Shrunk files
  243.  
  244.  
  245. B<Q:> I'm trying to extract a file out of a Zip produced by PKZIP, and keep
  246. getting this error message:
  247.  
  248.  
  249.   error: Unsupported compression combination: read 6, write 0
  250.  
  251.  
  252. B<A:> You can't uncompress this archive member. Archive::Zip only supports uncompressed
  253. members, and compressed members that are compressed using the compression
  254. supported by Compress::Zlib. That means only Deflated and Stored members.
  255.  
  256.  
  257. Your file is compressed using the Shrink format, which isn't supported by
  258. Compress::Zlib.
  259.  
  260.  
  261. You could, perhaps, use a command-line UnZip program (like the Info-Zip
  262. one) to extract this.
  263.  
  264. =head1 Can't do decryption
  265.  
  266.  
  267. B<Q:> How do I decrypt encrypted Zip members?
  268.  
  269.  
  270. B<A:> With some other program or library. Archive::Zip doesn't support decryption,
  271. and probably never will (unless I<you> write it).
  272.  
  273. =head1 How to test file integrity?
  274.  
  275.  
  276. B<Q:> How can Archive::Zip can test the validity of a Zip file?
  277.  
  278.  
  279. B<A:> If you try to decompress the file, the gzip streams will report errors 
  280. if you have garbage. Most of the time.
  281.  
  282. If you try to open the file and a central directory structure can't be 
  283. found, an error will be reported.
  284.  
  285. When a file is being read, if we can't find a proper PK.. signature in 
  286. the right places we report a format error.
  287.  
  288. If there is added garbage at the beginning of a Zip file (as inserted 
  289. by some viruses), you can find out about it, but Archive::Zip will ignore it, 
  290. and you can still use the archive. When it gets written back out the 
  291. added stuff will be gone.
  292.  
  293.  
  294. There are two ready-to-use utilities in the examples directory that can
  295. be used to test file integrity, or that you can use as examples
  296. for your own code:
  297.  
  298. =over 4
  299.  
  300. =item examples/zipcheck.pl shows how to use an attempted extraction to test a file.
  301.  
  302.  
  303.  
  304. =item examples/ziptest.pl shows how to test CRCs in a file.
  305.  
  306.  
  307.  
  308. =back
  309.  
  310. =head1 Duplicate files in Zip?
  311.  
  312.  
  313. B<Q:> Archive::Zip let me put the same file in my Zip twice! Why don't you prevent this?
  314.  
  315.  
  316. B<A:> As far as I can tell, this is not disallowed by the Zip spec. If you
  317. think it's a bad idea, check for it yourself:
  318.  
  319.  
  320.   $zip->addFile($someFile, $someName) unless $zip->memberNamed($someName);
  321.  
  322.  
  323. I can even imagine cases where this might be useful (for instance, multiple
  324. versions of files).
  325.  
  326. =head1 File ownership/permissions/ACLS/etc
  327.  
  328.  
  329. B<Q:> Why doesn't Archive::Zip deal with file ownership, ACLs, etc.?
  330.  
  331.  
  332. B<A:> There is no standard way to represent these in the Zip file format. If
  333. you want to send me code to properly handle the various extra fields that
  334. have been used to represent these through the years, I'll look at it.
  335.  
  336. =head1 I can't compile but AS only has an old version of Archive::Zip
  337.  
  338.  
  339. B<Q:> I've only installed modules using ActiveState's PPM program and
  340. repository. But they have a much older version of Archive::Zip than is in CPAN. Will
  341. you send me a newer PPM?
  342.  
  343.  
  344. B<A:> Probably not, unless I get lots of extra time. But there's no reason you
  345. can't install the version from CPAN. Archive::Zip is pure Perl, so all you need is
  346. NMAKE, which you can get for free from Microsoft (see the FAQ in the
  347. ActiveState documentation for details on how to install CPAN modules).
  348.  
  349. =head1 My JPEGs (or MP3's) don't compress when I put them into Zips!
  350.  
  351.  
  352. B<Q:> How come my JPEGs and MP3's don't compress much when I put them into Zips?
  353.  
  354.  
  355. B<A:> Because they're already compressed.
  356.  
  357. =head1 Under Windows, things lock up/get damaged
  358.  
  359.  
  360. B<Q:> I'm using Windows. When I try to use Archive::Zip, my machine locks up/makes
  361. funny sounds/displays a BSOD/corrupts data. How can I fix this?
  362.  
  363.  
  364. B<A:> First, try the newest version of Compress::Zlib. I know of
  365. Windows-related problems prior to v1.14 of that library.
  366.  
  367.  
  368. If that doesn't get rid of the problem, fix your computer or get rid of
  369. Windows.
  370.  
  371. =head1 Zip contents in a scalar
  372.  
  373.  
  374. B<Q:> I want to read a Zip file from (or write one to) a scalar variable instead
  375. of a file. How can I do this?
  376.  
  377.  
  378. B<A:> Use C<IO::Scalar> and the C<readFromFileHandle()> and
  379. C<writeToFileHandle()> methods.
  380. See C<examples/readScalar.pl> and C<examples/writeScalar.pl>.
  381.  
  382. =head1 Reading from streams
  383.  
  384.  
  385. B<Q:> How do I read from a stream (like for the Info-Zip C<funzip> program)?
  386.  
  387.  
  388. B<A:>    This isn't currently supported, though writing to a stream is.
  389.