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