File Coverage

blib/lib/IO/Uncompress/Unzip.pm
Criterion Covered Total %
statement 300 434 69.1
branch 107 214 50.0
condition 12 20 60.0
subroutine 33 39 84.6
pod 2 20 10.0
total 454 727 62.4


line stmt bran cond sub pod time code
1             package IO::Uncompress::Unzip;
2              
3             require 5.006 ;
4              
5             # for RFC1952
6              
7 83     83   8904 use strict ;
  83         165  
  83         3282  
8 83     83   418 use warnings;
  83         188  
  83         4235  
9 83     83   563 use bytes;
  83         1117  
  83         833  
10              
11 83     83   2572 use IO::File;
  83         168  
  83         16281  
12 83     83   5777 use IO::Uncompress::RawInflate 2.219 ;
  83         1722  
  83         4918  
13 83     83   527 use IO::Compress::Base::Common 2.219 qw(:Status );
  83         1387  
  83         12278  
14 83     83   557 use IO::Uncompress::Adapter::Inflate 2.219 ;
  83         1429  
  83         3329  
15 83     83   43734 use IO::Uncompress::Adapter::Identity 2.219 ;
  83         2004  
  83         3328  
16 83     83   613 use IO::Compress::Zlib::Extra 2.219 ;
  83         1302  
  83         2408  
17 83     83   404 use IO::Compress::Zip::Constants 2.219 ;
  83         947  
  83         19828  
18              
19 83     83   604 use Compress::Raw::Zlib 2.218 () ;
  83         1336  
  83         11443  
20              
21             BEGIN
22             {
23             # Don't trigger any __DIE__ Hooks.
24 83     83   570 local $SIG{__DIE__};
25              
26 83         1172 eval{ require IO::Uncompress::Adapter::Bunzip2 ;
  83         6589  
27 83         1529 IO::Uncompress::Adapter::Bunzip2->VERSION(2.219) } ;
28 83         217 eval{ require IO::Uncompress::Adapter::UnLzma ;
  83         12466  
29 0         0 IO::Uncompress::Adapter::UnLzma->VERSION(2.217) } ;
30 83         264 eval{ require IO::Uncompress::Adapter::UnXz ;
  83         8157  
31 0         0 IO::Uncompress::Adapter::UnXz->VERSION(2.217) } ;
32 83         240 eval{ require IO::Uncompress::Adapter::UnZstd ;
  83         414438  
33 0         0 IO::Uncompress::Adapter::UnZstd->VERSION(2.217) } ;
34             }
35              
36              
37             require Exporter ;
38              
39             our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $UnzipError, %headerLookup);
40              
41             $VERSION = '2.219';
42             $UnzipError = '';
43              
44             @ISA = qw(IO::Uncompress::RawInflate Exporter);
45             @EXPORT_OK = qw($UnzipError unzip );
46             %EXPORT_TAGS = %IO::Uncompress::RawInflate::EXPORT_TAGS ;
47             $EXPORT_TAGS{all} = [ defined $EXPORT_TAGS{all} ? @{ $EXPORT_TAGS{all} } : (), @EXPORT_OK ] ;
48             Exporter::export_ok_tags('all');
49              
50             %headerLookup = (
51             ZIP_CENTRAL_HDR_SIG, \&skipCentralDirectory,
52             ZIP_END_CENTRAL_HDR_SIG, \&skipEndCentralDirectory,
53             ZIP64_END_CENTRAL_REC_HDR_SIG, \&skipCentralDirectory64Rec,
54             ZIP64_END_CENTRAL_LOC_HDR_SIG, \&skipCentralDirectory64Loc,
55             ZIP64_ARCHIVE_EXTRA_SIG, \&skipArchiveExtra,
56             ZIP64_DIGITAL_SIGNATURE_SIG, \&skipDigitalSignature,
57             );
58              
59             my %MethodNames = (
60             ZIP_CM_DEFLATE() => 'Deflated',
61             ZIP_CM_BZIP2() => 'Bzip2',
62             ZIP_CM_LZMA() => 'Lzma',
63             ZIP_CM_STORE() => 'Stored',
64             ZIP_CM_XZ() => 'Xz',
65             ZIP_CM_ZSTD() => 'Zstd',
66             );
67              
68             sub new
69             {
70 315     315 1 298449 my $class = shift ;
71 315         1342 my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$UnzipError);
72 315         1495 $obj->_create(undef, 0, @_);
73             }
74              
75             sub unzip
76             {
77 172     172 1 132266 my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$UnzipError);
78 172         1136 return $obj->_inf(@_) ;
79             }
80              
81             sub getExtraParams
82             {
83              
84             return (
85             # # Zip header fields
86 470     470 0 6826 'name' => [IO::Compress::Base::Common::Parse_any, undef],
87              
88             'stream' => [IO::Compress::Base::Common::Parse_boolean, 0],
89             'efs' => [IO::Compress::Base::Common::Parse_boolean, 0],
90              
91             # TODO - This means reading the central directory to get
92             # 1. the local header offsets
93             # 2. The compressed data length
94             );
95             }
96              
97             sub ckParams
98             {
99 478     478 0 860 my $self = shift ;
100 478         808 my $got = shift ;
101              
102             # unzip always needs crc32
103 478         1872 $got->setValue('crc32' => 1);
104              
105 478         1329 *$self->{UnzipData}{Name} = $got->getValue('name');
106 478         1267 *$self->{UnzipData}{efs} = $got->getValue('efs');
107              
108 478         1596 return 1;
109             }
110              
111             sub mkUncomp
112             {
113 477     477 0 997 my $self = shift ;
114 477         1014 my $got = shift ;
115              
116 477 100       1627 my $magic = $self->ckMagic()
117             or return 0;
118              
119 423 100       1752 *$self->{Info} = $self->readHeader($magic)
120             or return undef ;
121              
122 420         1459 return 1;
123              
124             }
125              
126             sub ckMagic
127             {
128 1389     1389 0 3264 my $self = shift;
129              
130 1389         2249 my $magic ;
131 1389         5443 $self->smartReadExact(\$magic, 4);
132              
133 1389         3674 *$self->{HeaderPending} = $magic ;
134              
135 1389 100       4088 return $self->HeaderError("Minimum header size is " .
136             4 . " bytes")
137             if length $magic != 4 ;
138              
139 1342 100       4433 return $self->HeaderError("Bad Magic")
140             if ! _isZipMagic($magic) ;
141              
142 1018         4026 *$self->{Type} = 'zip';
143              
144 1018         8840 return $magic ;
145             }
146              
147              
148             sub fastForward
149             {
150 60     60 0 101 my $self = shift;
151 60         117 my $offset = shift;
152              
153             # TODO - if Stream isn't enabled & reading from file, use seek
154              
155 60         112 my $buffer = '';
156 60         100 my $c = 1024 * 16;
157              
158 60         157 while ($offset > 0)
159             {
160 1178 100       2581 $c = length $offset
161             if length $offset < $c ;
162              
163 1178         1893 $offset -= $c;
164              
165 1178 50       2629 $self->smartReadExact(\$buffer, $c)
166             or return 0;
167             }
168              
169 60         184 return 1;
170             }
171              
172              
173             sub readHeader
174             {
175 1018     1018 0 2159 my $self = shift;
176 1018         2571 my $magic = shift ;
177              
178 1018         2876 my $name = *$self->{UnzipData}{Name} ;
179 1018         4113 my $hdr = $self->_readZipHeader($magic) ;
180              
181 1017         3970 while (defined $hdr)
182             {
183 1052 100 100     3777 if (! defined $name || $hdr->{Name} eq $name)
184             {
185 1015         6220 return $hdr ;
186             }
187              
188             # skip the data
189             # TODO - when Stream is off, use seek
190 37         60 my $buffer;
191 37 100       127 if (*$self->{ZipData}{Streaming}) {
192 11         21 while (1) {
193              
194 12         25 my $b;
195 12         68 my $status = $self->smartRead(\$b, 1024 * 16);
196              
197 12 50       45 return $self->saveErrorString(undef, "Truncated file")
198             if $status <= 0 ;
199              
200 12         25 my $temp_buf ;
201             my $out;
202              
203 12         75 $status = *$self->{Uncomp}->uncompr(\$b, \$temp_buf, 0, $out);
204              
205             return $self->saveErrorString(undef, *$self->{Uncomp}{Error},
206             *$self->{Uncomp}{ErrorNo})
207 12 50       148 if $self->saveStatus($status) == STATUS_ERROR;
208              
209 12         51 $self->pushBack($b) ;
210              
211 12 100       42 if ($status == STATUS_ENDSTREAM) {
212 11         57 *$self->{Uncomp}->reset();
213 11         30 last;
214             }
215             }
216              
217             # skip the trailer
218             $self->smartReadExact(\$buffer, $hdr->{TrailerLength})
219 11 50       49 or return $self->saveErrorString(undef, "Truncated file");
220             }
221             else {
222 26         96 my $c = $hdr->{CompressedLength}->get64bit();
223 26 50       81 $self->fastForward($c)
224             or return $self->saveErrorString(undef, "Truncated file");
225 26         86 $buffer = '';
226             }
227              
228 37 50       110 $self->chkTrailer($buffer) == STATUS_OK
229             or return $self->saveErrorString(undef, "Truncated file");
230              
231 37         123 $hdr = $self->_readFullZipHeader();
232              
233 37 50       223 return $self->saveErrorString(undef, "Cannot find '$name'")
234             if $self->smartEof();
235             }
236              
237 2         9 return undef;
238             }
239              
240             sub chkTrailer
241             {
242 1041     1041 0 1958 my $self = shift;
243 1041         2225 my $trailer = shift;
244              
245 1041         4358 my ($sig, $CRC32, $cSize, $uSize) ;
246 1041         4777 my ($cSizeHi, $uSizeHi) = (0, 0);
247 1041 100       3487 if (*$self->{ZipData}{Streaming}) {
248 939         3670 $sig = unpack ("V", substr($trailer, 0, 4));
249 939         2479 $CRC32 = unpack ("V", substr($trailer, 4, 4));
250              
251 939 100       2849 if (*$self->{ZipData}{Zip64} ) {
252 31         137 $cSize = U64::newUnpack_V64 substr($trailer, 8, 8);
253 31         106 $uSize = U64::newUnpack_V64 substr($trailer, 16, 8);
254             }
255             else {
256 908         3943 $cSize = U64::newUnpack_V32 substr($trailer, 8, 4);
257 908         3945 $uSize = U64::newUnpack_V32 substr($trailer, 12, 4);
258             }
259              
260 939 100       3633 return $self->TrailerError("Data Descriptor signature, got $sig")
261             if $sig != ZIP_DATA_HDR_SIG;
262             }
263             else {
264             ($CRC32, $cSize, $uSize) =
265             (*$self->{ZipData}{Crc32},
266             *$self->{ZipData}{CompressedLen},
267 102         391 *$self->{ZipData}{UnCompressedLen});
268             }
269              
270 1039         3156 *$self->{Info}{CRC32} = *$self->{ZipData}{CRC32} ;
271 1039         3490 *$self->{Info}{CompressedLength} = $cSize->get64bit();
272 1039         2912 *$self->{Info}{UncompressedLength} = $uSize->get64bit();
273              
274 1039 100       3432 if (*$self->{Strict}) {
275             return $self->TrailerError("CRC mismatch")
276 489 50       1432 if $CRC32 != *$self->{ZipData}{CRC32} ;
277              
278             return $self->TrailerError("CSIZE mismatch.")
279 489 50       1834 if ! $cSize->equal(*$self->{CompSize});
280              
281             return $self->TrailerError("USIZE mismatch.")
282 489 50       1443 if ! $uSize->equal(*$self->{UnCompSize});
283             }
284              
285 1039         2080 my $reachedEnd = STATUS_ERROR ;
286             # check for central directory or end of central directory
287 1039         1886 while (1)
288             {
289 2113         3019 my $magic ;
290 2113         6013 my $got = $self->smartRead(\$magic, 4);
291              
292             return $self->saveErrorString(STATUS_ERROR, "Truncated file")
293 2113 0 33     8255 if $got != 4 && *$self->{Strict};
294              
295 2113 50       7806 if ($got == 0) {
    50          
    50          
296 0         0 return STATUS_EOF ;
297             }
298             elsif ($got < 0) {
299 0         0 return STATUS_ERROR ;
300             }
301             elsif ($got < 4) {
302 0         0 $self->pushBack($magic) ;
303 0         0 return STATUS_OK ;
304             }
305              
306 2113         4938 my $sig = unpack("V", $magic) ;
307              
308 2113         3455 my $hdr;
309 2113 100       10775 if ($hdr = $headerLookup{$sig})
    50          
310             {
311 1725 50       5001 if (&$hdr($self, $magic) != STATUS_OK ) {
312 0 0       0 if (*$self->{Strict}) {
313 0         0 return STATUS_ERROR ;
314             }
315             else {
316 0         0 $self->clearError();
317 0         0 return STATUS_OK ;
318             }
319             }
320              
321 1725 100       7343 if ($sig == ZIP_END_CENTRAL_HDR_SIG)
322             {
323 651         3997 return STATUS_OK ;
324 0         0 last;
325             }
326             }
327             elsif ($sig == ZIP_LOCAL_HDR_SIG)
328             {
329 388         1280 $self->pushBack($magic) ;
330 388         2038 return STATUS_OK ;
331             }
332             else
333             {
334             # put the data back
335 0         0 $self->pushBack($magic) ;
336 0         0 last;
337             }
338             }
339              
340 0         0 return $reachedEnd ;
341             }
342              
343             sub skipCentralDirectory
344             {
345 1006     1006 0 2935 my $self = shift;
346 1006         3640 my $magic = shift ;
347              
348 1006         1665 my $buffer;
349 1006 50       3334 $self->smartReadExact(\$buffer, 46 - 4)
350             or return $self->TrailerError("Minimum header size is " .
351             46 . " bytes") ;
352              
353 1006         2575 my $keep = $magic . $buffer ;
354 1006         2649 *$self->{HeaderPending} = $keep ;
355              
356             #my $versionMadeBy = unpack ("v", substr($buffer, 4-4, 2));
357             #my $extractVersion = unpack ("v", substr($buffer, 6-4, 2));
358             #my $gpFlag = unpack ("v", substr($buffer, 8-4, 2));
359             #my $compressedMethod = unpack ("v", substr($buffer, 10-4, 2));
360             #my $lastModTime = unpack ("V", substr($buffer, 12-4, 4));
361             #my $crc32 = unpack ("V", substr($buffer, 16-4, 4));
362 1006         2897 my $compressedLength = unpack ("V", substr($buffer, 20-4, 4));
363 1006         2640 my $uncompressedLength = unpack ("V", substr($buffer, 24-4, 4));
364 1006         2457 my $filename_length = unpack ("v", substr($buffer, 28-4, 2));
365 1006         2394 my $extra_length = unpack ("v", substr($buffer, 30-4, 2));
366 1006         2500 my $comment_length = unpack ("v", substr($buffer, 32-4, 2));
367             #my $disk_start = unpack ("v", substr($buffer, 34-4, 2));
368             #my $int_file_attrib = unpack ("v", substr($buffer, 36-4, 2));
369             #my $ext_file_attrib = unpack ("V", substr($buffer, 38-4, 2));
370             #my $lcl_hdr_offset = unpack ("V", substr($buffer, 42-4, 2));
371              
372              
373 1006         2895 my $filename;
374             my $extraField;
375 1006         0 my $comment ;
376 1006 100       2409 if ($filename_length)
377             {
378 240 50       762 $self->smartReadExact(\$filename, $filename_length)
379             or return $self->TruncatedTrailer("filename");
380 240         583 $keep .= $filename ;
381             }
382              
383 1006 100       2430 if ($extra_length)
384             {
385 166 50       513 $self->smartReadExact(\$extraField, $extra_length)
386             or return $self->TruncatedTrailer("extra");
387 166         338 $keep .= $extraField ;
388             }
389              
390 1006 100       2693 if ($comment_length)
391             {
392 1 50       2 $self->smartReadExact(\$comment, $comment_length)
393             or return $self->TruncatedTrailer("comment");
394 1         1 $keep .= $comment ;
395             }
396              
397 1006         3377 return STATUS_OK ;
398             }
399              
400             sub skipArchiveExtra
401             {
402 0     0 0 0 my $self = shift;
403 0         0 my $magic = shift ;
404              
405 0         0 my $buffer;
406 0 0       0 $self->smartReadExact(\$buffer, 4)
407             or return $self->TrailerError("Minimum header size is " .
408             4 . " bytes") ;
409              
410 0         0 my $keep = $magic . $buffer ;
411              
412 0         0 my $size = unpack ("V", $buffer);
413              
414 0 0       0 $self->smartReadExact(\$buffer, $size)
415             or return $self->TrailerError("Minimum header size is " .
416             $size . " bytes") ;
417              
418 0         0 $keep .= $buffer ;
419 0         0 *$self->{HeaderPending} = $keep ;
420              
421 0         0 return STATUS_OK ;
422             }
423              
424              
425             sub skipCentralDirectory64Rec
426             {
427 34     34 0 65 my $self = shift;
428 34         59 my $magic = shift ;
429              
430 34         56 my $buffer;
431 34 50       99 $self->smartReadExact(\$buffer, 8)
432             or return $self->TrailerError("Minimum header size is " .
433             8 . " bytes") ;
434              
435 34         99 my $keep = $magic . $buffer ;
436              
437 34         125 my ($sizeLo, $sizeHi) = unpack ("V V", $buffer);
438 34         79 my $size = $sizeHi * U64::MAX32 + $sizeLo;
439              
440 34 50       91 $self->fastForward($size)
441             or return $self->TrailerError("Minimum header size is " .
442             $size . " bytes") ;
443              
444             #$keep .= $buffer ;
445             #*$self->{HeaderPending} = $keep ;
446              
447             #my $versionMadeBy = unpack ("v", substr($buffer, 0, 2));
448             #my $extractVersion = unpack ("v", substr($buffer, 2, 2));
449             #my $diskNumber = unpack ("V", substr($buffer, 4, 4));
450             #my $cntrlDirDiskNo = unpack ("V", substr($buffer, 8, 4));
451             #my $entriesInThisCD = unpack ("V V", substr($buffer, 12, 8));
452             #my $entriesInCD = unpack ("V V", substr($buffer, 20, 8));
453             #my $sizeOfCD = unpack ("V V", substr($buffer, 28, 8));
454             #my $offsetToCD = unpack ("V V", substr($buffer, 36, 8));
455              
456 34         115 return STATUS_OK ;
457             }
458              
459             sub skipCentralDirectory64Loc
460             {
461 34     34 0 67 my $self = shift;
462 34         59 my $magic = shift ;
463              
464 34         58 my $buffer;
465 34 50       98 $self->smartReadExact(\$buffer, 20 - 4)
466             or return $self->TrailerError("Minimum header size is " .
467             20 . " bytes") ;
468              
469 34         76 my $keep = $magic . $buffer ;
470 34         93 *$self->{HeaderPending} = $keep ;
471              
472             #my $startCdDisk = unpack ("V", substr($buffer, 4-4, 4));
473             #my $offsetToCD = unpack ("V V", substr($buffer, 8-4, 8));
474             #my $diskCount = unpack ("V", substr($buffer, 16-4, 4));
475              
476 34         101 return STATUS_OK ;
477             }
478              
479             sub skipEndCentralDirectory
480             {
481 651     651 0 1271 my $self = shift;
482 651         1185 my $magic = shift ;
483              
484              
485 651         1696 my $buffer;
486 651 50       2175 $self->smartReadExact(\$buffer, 22 - 4)
487             or return $self->TrailerError("Minimum header size is " .
488             22 . " bytes") ;
489              
490 651         1634 my $keep = $magic . $buffer ;
491 651         1749 *$self->{HeaderPending} = $keep ;
492              
493             #my $diskNumber = unpack ("v", substr($buffer, 4-4, 2));
494             #my $cntrlDirDiskNo = unpack ("v", substr($buffer, 6-4, 2));
495             #my $entriesInThisCD = unpack ("v", substr($buffer, 8-4, 2));
496             #my $entriesInCD = unpack ("v", substr($buffer, 10-4, 2));
497             #my $sizeOfCD = unpack ("V", substr($buffer, 12-4, 4));
498             #my $offsetToCD = unpack ("V", substr($buffer, 16-4, 4));
499 651         2050 my $comment_length = unpack ("v", substr($buffer, 20-4, 2));
500              
501              
502 651         1386 my $comment ;
503 651 50       1799 if ($comment_length)
504             {
505 0 0       0 $self->smartReadExact(\$comment, $comment_length)
506             or return $self->TruncatedTrailer("comment");
507 0         0 $keep .= $comment ;
508             }
509              
510 651         1769 return STATUS_OK ;
511             }
512              
513              
514             sub _isZipMagic
515             {
516 1379     1379   2601 my $buffer = shift ;
517 1379 50       3514 return 0 if length $buffer < 4 ;
518 1379         4563 my $sig = unpack("V", $buffer) ;
519 1379         5525 return $sig == ZIP_LOCAL_HDR_SIG ;
520             }
521              
522              
523             sub _readFullZipHeader($)
524             {
525 37     37   92 my ($self) = @_ ;
526 37         83 my $magic = '' ;
527              
528 37         121 $self->smartReadExact(\$magic, 4);
529              
530 37         111 *$self->{HeaderPending} = $magic ;
531              
532 37 50       105 return $self->HeaderError("Minimum header size is " .
533             30 . " bytes")
534             if length $magic != 4 ;
535              
536              
537 37 50       104 return $self->HeaderError("Bad Magic")
538             if ! _isZipMagic($magic) ;
539              
540 37         135 my $status = $self->_readZipHeader($magic);
541 37 50       143 delete *$self->{Transparent} if ! defined $status ;
542 37         316 return $status ;
543             }
544              
545             sub _readZipHeader($)
546             {
547 1055     1055   3336 my ($self, $magic) = @_ ;
548 1055         1815 my ($HeaderCRC) ;
549 1055         2425 my ($buffer) = '' ;
550              
551 1055 50       3474 $self->smartReadExact(\$buffer, 30 - 4)
552             or return $self->HeaderError("Minimum header size is " .
553             30 . " bytes") ;
554              
555 1055         3106 my $keep = $magic . $buffer ;
556 1055         3034 *$self->{HeaderPending} = $keep ;
557              
558 1055         5050 my $extractVersion = unpack ("v", substr($buffer, 4-4, 2));
559 1055         5140 my $gpFlag = unpack ("v", substr($buffer, 6-4, 2));
560 1055         5729 my $compressedMethod = unpack ("v", substr($buffer, 8-4, 2));
561 1055         2673 my $lastModTime = unpack ("V", substr($buffer, 10-4, 4));
562 1055         2472 my $crc32 = unpack ("V", substr($buffer, 14-4, 4));
563 1055         5763 my $compressedLength = U64::newUnpack_V32 substr($buffer, 18-4, 4);
564 1055         3921 my $uncompressedLength = U64::newUnpack_V32 substr($buffer, 22-4, 4);
565 1055         2893 my $filename_length = unpack ("v", substr($buffer, 26-4, 2));
566 1055         2600 my $extra_length = unpack ("v", substr($buffer, 28-4, 2));
567              
568 1055         2380 my $filename;
569             my $extraField;
570 1055         2353 my @EXTRA = ();
571              
572             # Some programs (some versions of LibreOffice) mark entries as streamed, but still fill out
573             # compressedLength/uncompressedLength & crc32 in the local file header.
574             # The expected data descriptor is not populated.
575             # So only assume streaming if the Streaming bit is set AND the compressed length is zero
576 1055 100 100     5886 my $streamingMode = (($gpFlag & ZIP_GP_FLAG_STREAMING_MASK) && $crc32 == 0) ? 1 : 0 ;
577              
578 1055 100       3060 my $efs_flag = ($gpFlag & ZIP_GP_FLAG_LANGUAGE_ENCODING) ? 1 : 0;
579              
580 1055 100       2940 return $self->HeaderError("Encrypted content not supported")
581             if $gpFlag & (ZIP_GP_FLAG_ENCRYPTED_MASK|ZIP_GP_FLAG_STRONG_ENCRYPTED_MASK);
582              
583 1053 50       3416 return $self->HeaderError("Patch content not supported")
584             if $gpFlag & ZIP_GP_FLAG_PATCHED_MASK;
585              
586 1053         4208 *$self->{ZipData}{Streaming} = $streamingMode;
587              
588              
589 1053 100       2740 if ($filename_length)
590             {
591 278 50       1017 $self->smartReadExact(\$filename, $filename_length)
592             or return $self->TruncatedHeader("Filename");
593              
594 278 50 66     1372 if (*$self->{UnzipData}{efs} && $efs_flag && $] >= 5.008004)
      66        
595             {
596 5         45 require Encode;
597 5 100       13 eval { $filename = Encode::decode_utf8($filename, 1) }
  5         97  
598             or Carp::croak "Zip Filename not UTF-8" ;
599             }
600              
601 277         870 $keep .= $filename ;
602             }
603              
604 1052         2003 my $zip64 = 0 ;
605              
606 1052 100       2657 if ($extra_length)
607             {
608 197 50       624 $self->smartReadExact(\$extraField, $extra_length)
609             or return $self->TruncatedHeader("Extra Field");
610              
611 197         5149 my $bad = IO::Compress::Zlib::Extra::parseRawExtra($extraField,
612             \@EXTRA, 1, 0);
613 197 50       506 return $self->HeaderError($bad)
614             if defined $bad;
615              
616 197         577 $keep .= $extraField ;
617              
618 197         380 my %Extra ;
619 197         559 for (@EXTRA)
620             {
621 400         1316 $Extra{$_->[0]} = \$_->[1];
622             }
623              
624 197 100       927 if (defined $Extra{ZIP_EXTRA_ID_ZIP64()})
625             {
626 47         77 $zip64 = 1 ;
627              
628 47         73 my $buff = ${ $Extra{ZIP_EXTRA_ID_ZIP64()} };
  47         107  
629              
630             # This code assumes that all the fields in the Zip64
631             # extra field aren't necessarily present. The spec says that
632             # they only exist if the equivalent local headers are -1.
633              
634 47 100       178 if (! $streamingMode) {
635 16         23 my $offset = 0 ;
636              
637 16 50       59 if (U64::full32 $uncompressedLength->get32bit() ) {
638 16         62 $uncompressedLength
639             = U64::newUnpack_V64 substr($buff, 0, 8);
640              
641 16         43 $offset += 8 ;
642             }
643              
644 16 50       42 if (U64::full32 $compressedLength->get32bit() ) {
645              
646 16         68 $compressedLength
647             = U64::newUnpack_V64 substr($buff, $offset, 8);
648              
649 16         71 $offset += 8 ;
650             }
651             }
652             }
653             }
654              
655 1052         3111 *$self->{ZipData}{Zip64} = $zip64;
656              
657 1052 100       2697 if (! $streamingMode) {
658 110         259 *$self->{ZipData}{Streaming} = 0;
659 110         292 *$self->{ZipData}{Crc32} = $crc32;
660 110         1813 *$self->{ZipData}{CompressedLen} = $compressedLength;
661 110         288 *$self->{ZipData}{UnCompressedLen} = $uncompressedLength;
662             *$self->{CompressedInputLengthRemaining} =
663 110         396 *$self->{CompressedInputLength} = $compressedLength->get64bit();
664             }
665              
666 1052         5748 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(undef);
667 1052         3320 *$self->{ZipData}{Method} = $compressedMethod;
668 1052 100       3513 if ($compressedMethod == ZIP_CM_DEFLATE)
    100          
    50          
    50          
    50          
    50          
669             {
670 943         2481 *$self->{Type} = 'zip-deflate';
671 943         6587 my $obj = IO::Uncompress::Adapter::Inflate::mkUncompObject(1,0,0);
672              
673 943         5210 *$self->{Uncomp} = $obj;
674             }
675             elsif ($compressedMethod == ZIP_CM_BZIP2)
676             {
677 32 50       115 return $self->HeaderError("Unsupported Compression format $compressedMethod")
678             if ! defined $IO::Uncompress::Adapter::Bunzip2::VERSION ;
679              
680 32         90 *$self->{Type} = 'zip-bzip2';
681              
682 32         176 my $obj = IO::Uncompress::Adapter::Bunzip2::mkUncompObject();
683              
684 32         165 *$self->{Uncomp} = $obj;
685             }
686             elsif ($compressedMethod == ZIP_CM_XZ)
687             {
688 0 0       0 return $self->HeaderError("Unsupported Compression format $compressedMethod")
689             if ! defined $IO::Uncompress::Adapter::UnXz::VERSION ;
690              
691 0         0 *$self->{Type} = 'zip-xz';
692              
693 0         0 my $obj = IO::Uncompress::Adapter::UnXz::mkUncompObject();
694              
695 0         0 *$self->{Uncomp} = $obj;
696             }
697             elsif ($compressedMethod == ZIP_CM_ZSTD)
698             {
699 0 0       0 return $self->HeaderError("Unsupported Compression format $compressedMethod")
700             if ! defined $IO::Uncompress::Adapter::UnZstd::VERSION ;
701              
702 0         0 *$self->{Type} = 'zip-zstd';
703              
704 0         0 my $obj = IO::Uncompress::Adapter::UnZstd::mkUncompObject();
705              
706 0         0 *$self->{Uncomp} = $obj;
707             }
708             elsif ($compressedMethod == ZIP_CM_LZMA)
709             {
710 0 0       0 return $self->HeaderError("Unsupported Compression format $compressedMethod")
711             if ! defined $IO::Uncompress::Adapter::UnLzma::VERSION ;
712              
713 0         0 *$self->{Type} = 'zip-lzma';
714 0         0 my $LzmaHeader;
715 0 0       0 $self->smartReadExact(\$LzmaHeader, 4)
716             or return $self->saveErrorString(undef, "Truncated file");
717 0         0 my ($verHi, $verLo) = unpack ("CC", substr($LzmaHeader, 0, 2));
718 0         0 my $LzmaPropertiesSize = unpack ("v", substr($LzmaHeader, 2, 2));
719              
720              
721 0         0 my $LzmaPropertyData;
722 0 0       0 $self->smartReadExact(\$LzmaPropertyData, $LzmaPropertiesSize)
723             or return $self->saveErrorString(undef, "Truncated file");
724              
725 0 0       0 if (! $streamingMode) {
726 0         0 *$self->{ZipData}{CompressedLen}->subtract(4 + $LzmaPropertiesSize) ;
727             *$self->{CompressedInputLengthRemaining} =
728 0         0 *$self->{CompressedInputLength} = *$self->{ZipData}{CompressedLen}->get64bit();
729             }
730              
731 0         0 my $obj =
732             IO::Uncompress::Adapter::UnLzma::mkUncompZipObject($LzmaPropertyData);
733              
734 0         0 *$self->{Uncomp} = $obj;
735             }
736             elsif ($compressedMethod == ZIP_CM_STORE)
737             {
738 77         209 *$self->{Type} = 'zip-stored';
739              
740 77         324 my $obj =
741             IO::Uncompress::Adapter::Identity::mkUncompObject($streamingMode,
742             $zip64);
743              
744 77         335 *$self->{Uncomp} = $obj;
745             }
746             else
747             {
748 0         0 return $self->HeaderError("Unsupported Compression format $compressedMethod");
749             }
750              
751             return {
752             'Type' => 'zip',
753             'FingerprintLength' => 4,
754             #'HeaderLength' => $compressedMethod == 8 ? length $keep : 0,
755             'HeaderLength' => length $keep,
756             'Zip64' => $zip64,
757             'TrailerLength' => ! $streamingMode ? 0 : $zip64 ? 24 : 16,
758             'Header' => $keep,
759             'CompressedLength' => $compressedLength ,
760             'UncompressedLength' => $uncompressedLength ,
761             'CRC32' => $crc32 ,
762             'Name' => $filename,
763             'efs' => $efs_flag, # language encoding flag
764             'Time' => _dosToUnixTime($lastModTime),
765             'Stream' => $streamingMode,
766              
767             'MethodID' => $compressedMethod,
768 1052 100 50     6862 'MethodName' => $MethodNames{$compressedMethod} || 'Unknown',
    100          
769              
770             # 'TextFlag' => $flag & GZIP_FLG_FTEXT ? 1 : 0,
771             # 'HeaderCRCFlag' => $flag & GZIP_FLG_FHCRC ? 1 : 0,
772             # 'NameFlag' => $flag & GZIP_FLG_FNAME ? 1 : 0,
773             # 'CommentFlag' => $flag & GZIP_FLG_FCOMMENT ? 1 : 0,
774             # 'ExtraFlag' => $flag & GZIP_FLG_FEXTRA ? 1 : 0,
775             # 'Comment' => $comment,
776             # 'OsID' => $os,
777             # 'OsName' => defined $GZIP_OS_Names{$os}
778             # ? $GZIP_OS_Names{$os} : "Unknown",
779             # 'HeaderCRC' => $HeaderCRC,
780             # 'Flags' => $flag,
781             # 'ExtraFlags' => $xfl,
782             'ExtraFieldRaw' => $extraField,
783             'ExtraField' => [ @EXTRA ],
784              
785              
786             }
787             }
788              
789             sub filterUncompressed
790             {
791 1222     1222 0 4984 my $self = shift ;
792              
793 1222 100       4145 if (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
794 1125         5658 *$self->{ZipData}{CRC32} = *$self->{Uncomp}->crc32() ;
795             }
796             else {
797 97         179 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(${$_[0]}, *$self->{ZipData}{CRC32}, $_[1]);
  97         2214  
798             }
799             }
800              
801              
802             # from Archive::Zip & info-zip
803             sub _dosToUnixTime
804             {
805             # Returns zero when $dt is already zero or it doesn't expand to a value that Time::Local::timelocal()
806             # can handle.
807              
808 1052     1052   2091 my $dt = shift;
809             # warn "_dosToUnixTime dt=[$dt]\n";
810              
811             # some zip files don't populate the datetime field at all
812 1052 100       3027 return 0 if ! $dt;
813              
814 1051         2757 my $year = ( ( $dt >> 25 ) & 0x7f ) + 80;
815 1051         2529 my $mon = ( ( $dt >> 21 ) & 0x0f ) - 1;
816 1051         2253 my $mday = ( ( $dt >> 16 ) & 0x1f );
817              
818 1051         2230 my $hour = ( ( $dt >> 11 ) & 0x1f );
819 1051         1934 my $min = ( ( $dt >> 5 ) & 0x3f );
820 1051         2284 my $sec = ( ( $dt << 1 ) & 0x3e );
821              
822 83     83   55940 use Time::Local ;
  83         200720  
  83         15829  
823              
824 1051         1759 my $time_t ;
825             # wrap in an eval to catch out of range errors
826 1051         2529 eval {
827 1051         6528 $time_t = Time::Local::timelocal( $sec, $min, $hour, $mday, $mon, $year);
828             } ;
829              
830 1051 100       110720 return 0 if ! defined $time_t;
831 1050         21166 return $time_t;
832             }
833              
834             #sub scanCentralDirectory
835             #{
836             # # Use cases
837             # # 1 32-bit CD
838             # # 2 64-bit CD
839             #
840             # my $self = shift ;
841             #
842             # my @CD = ();
843             # my $offset = $self->findCentralDirectoryOffset();
844             #
845             # return 0
846             # if ! defined $offset;
847             #
848             # $self->smarkSeek($offset, 0, SEEK_SET) ;
849             #
850             # # Now walk the Central Directory Records
851             # my $buffer ;
852             # while ($self->smartReadExact(\$buffer, 46) &&
853             # unpack("V", $buffer) == ZIP_CENTRAL_HDR_SIG) {
854             #
855             # my $compressedLength = unpack ("V", substr($buffer, 20, 4));
856             # my $filename_length = unpack ("v", substr($buffer, 28, 2));
857             # my $extra_length = unpack ("v", substr($buffer, 30, 2));
858             # my $comment_length = unpack ("v", substr($buffer, 32, 2));
859             #
860             # $self->smarkSeek($filename_length + $extra_length + $comment_length, 0, SEEK_CUR)
861             # if $extra_length || $comment_length || $filename_length;
862             # push @CD, $compressedLength ;
863             # }
864             #
865             #}
866             #
867             #sub findCentralDirectoryOffset
868             #{
869             # my $self = shift ;
870             #
871             # # Most common use-case is where there is no comment, so
872             # # know exactly where the end of central directory record
873             # # should be.
874             #
875             # $self->smarkSeek(-22, 0, SEEK_END) ;
876             #
877             # my $buffer;
878             # $self->smartReadExact(\$buffer, 22) ;
879             #
880             # my $zip64 = 0;
881             # my $centralDirOffset ;
882             # if ( unpack("V", $buffer) == ZIP_END_CENTRAL_HDR_SIG ) {
883             # $centralDirOffset = unpack ("V", substr($buffer, 16, 2));
884             # }
885             # else {
886             # die "xxxx";
887             # }
888             #
889             # return $centralDirOffset ;
890             #}
891             #
892             #sub is84BitCD
893             #{
894             # # TODO
895             # my $self = shift ;
896             #}
897              
898              
899             sub skip
900             {
901 0     0 0   my $self = shift;
902 0           my $size = shift;
903              
904 83     83   685 use Fcntl qw(SEEK_CUR);
  83         173  
  83         79501  
905 0 0         if (ref $size eq 'U64') {
906 0           $self->smartSeek($size->get64bit(), SEEK_CUR);
907             }
908             else {
909 0           $self->smartSeek($size, SEEK_CUR);
910             }
911              
912             }
913              
914              
915             sub scanCentralDirectory
916             {
917 0     0 0   my $self = shift;
918              
919 0           my $here = $self->tell();
920              
921             # Use cases
922             # 1 32-bit CD
923             # 2 64-bit CD
924              
925 0           my @CD = ();
926 0           my $offset = $self->findCentralDirectoryOffset();
927              
928             return ()
929 0 0         if ! defined $offset;
930              
931 0           $self->smarkSeek($offset, 0, SEEK_SET) ;
932              
933             # Now walk the Central Directory Records
934 0           my $buffer ;
935 0   0       while ($self->smartReadExact(\$buffer, 46) &&
936             unpack("V", $buffer) == ZIP_CENTRAL_HDR_SIG) {
937              
938 0           my $compressedLength = unpack("V", substr($buffer, 20, 4));
939 0           my $uncompressedLength = unpack("V", substr($buffer, 24, 4));
940 0           my $filename_length = unpack("v", substr($buffer, 28, 2));
941 0           my $extra_length = unpack("v", substr($buffer, 30, 2));
942 0           my $comment_length = unpack("v", substr($buffer, 32, 2));
943              
944 0           $self->skip($filename_length ) ;
945              
946 0           my $v64 = U64->new( $compressedLength );
947              
948 0 0         if (U64::full32 $compressedLength ) {
949 0           $self->smartReadExact(\$buffer, $extra_length) ;
950 0 0         die "xxx $offset $comment_length $filename_length $extra_length" . length($buffer)
951             if length($buffer) != $extra_length;
952 0           my $got = $self->get64Extra($buffer, U64::full32 $uncompressedLength);
953              
954             # If not Zip64 extra field, assume size is 0xFFFFFFFF
955 0 0         $v64 = $got if defined $got;
956             }
957             else {
958 0           $self->skip($extra_length) ;
959             }
960              
961 0           $self->skip($comment_length ) ;
962              
963 0           push @CD, $v64 ;
964             }
965              
966 0           $self->smartSeek($here, 0, SEEK_SET) ;
967              
968 0           return @CD;
969             }
970              
971             sub get64Extra
972             {
973 0     0 0   my $self = shift ;
974              
975 0           my $buffer = shift;
976 0           my $is_uncomp = shift ;
977              
978 0           my $extra = IO::Compress::Zlib::Extra::findID(0x0001, $buffer);
979              
980 0 0         if (! defined $extra)
981             {
982 0           return undef;
983             }
984             else
985             {
986 0 0         my $u64 = U64::newUnpack_V64(substr($extra, $is_uncomp ? 8 : 0)) ;
987 0           return $u64;
988             }
989             }
990              
991             sub offsetFromZip64
992             {
993 0     0 0   my $self = shift ;
994 0           my $here = shift;
995              
996 0 0         $self->smartSeek($here - 20, 0, SEEK_SET)
997             or die "xx $!" ;
998              
999 0           my $buffer;
1000 0           my $got = 0;
1001 0 0         $self->smartReadExact(\$buffer, 20)
1002             or die "xxx $here $got $!" ;
1003              
1004 0 0         if ( unpack("V", $buffer) == ZIP64_END_CENTRAL_LOC_HDR_SIG ) {
1005 0           my $cd64 = U64::Value_VV64 substr($buffer, 8, 8);
1006              
1007 0           $self->smartSeek($cd64, 0, SEEK_SET) ;
1008              
1009 0 0         $self->smartReadExact(\$buffer, 4)
1010             or die "xxx" ;
1011              
1012 0 0         if ( unpack("V", $buffer) == ZIP64_END_CENTRAL_REC_HDR_SIG ) {
1013              
1014 0 0         $self->smartReadExact(\$buffer, 8)
1015             or die "xxx" ;
1016 0           my $size = U64::Value_VV64($buffer);
1017 0 0         $self->smartReadExact(\$buffer, $size)
1018             or die "xxx" ;
1019              
1020 0           my $cd64 = U64::Value_VV64 substr($buffer, 36, 8);
1021              
1022 0           return $cd64 ;
1023             }
1024              
1025 0           die "zzz";
1026             }
1027              
1028 0           die "zzz";
1029             }
1030              
1031 83     83   813 use constant Pack_ZIP_END_CENTRAL_HDR_SIG => pack("V", ZIP_END_CENTRAL_HDR_SIG);
  83         225  
  83         36584  
1032              
1033             sub findCentralDirectoryOffset
1034             {
1035 0     0 0   my $self = shift ;
1036              
1037             # Most common use-case is where there is no comment, so
1038             # know exactly where the end of central directory record
1039             # should be.
1040              
1041 0           $self->smartSeek(-22, 0, SEEK_END) ;
1042 0           my $here = $self->tell();
1043              
1044 0           my $buffer;
1045 0 0         $self->smartReadExact(\$buffer, 22)
1046             or die "xxx" ;
1047              
1048 0           my $zip64 = 0;
1049 0           my $centralDirOffset ;
1050 0 0         if ( unpack("V", $buffer) == ZIP_END_CENTRAL_HDR_SIG ) {
1051 0           $centralDirOffset = unpack("V", substr($buffer, 16, 4));
1052             }
1053             else {
1054 0           $self->smartSeek(0, 0, SEEK_END) ;
1055              
1056 0           my $fileLen = $self->tell();
1057 0           my $want = 0 ;
1058              
1059 0           while(1) {
1060 0           $want += 1024;
1061 0           my $seekTo = $fileLen - $want;
1062 0 0         if ($seekTo < 0 ) {
1063 0           $seekTo = 0;
1064 0           $want = $fileLen ;
1065             }
1066 0 0         $self->smartSeek( $seekTo, 0, SEEK_SET)
1067             or die "xxx $!" ;
1068 0           my $got;
1069 0 0         $self->smartReadExact($buffer, $want)
1070             or die "xxx " ;
1071 0           my $pos = rindex( $buffer, Pack_ZIP_END_CENTRAL_HDR_SIG);
1072              
1073 0 0         if ($pos >= 0) {
1074             #$here = $self->tell();
1075 0           $here = $seekTo + $pos ;
1076 0           $centralDirOffset = unpack("V", substr($buffer, $pos + 16, 4));
1077 0           last ;
1078             }
1079              
1080             return undef
1081 0 0         if $want == $fileLen;
1082             }
1083             }
1084              
1085 0 0         $centralDirOffset = $self->offsetFromZip64($here)
1086             if U64::full32 $centralDirOffset ;
1087              
1088 0           return $centralDirOffset ;
1089             }
1090              
1091             1;
1092              
1093             __END__
1094              
1095              
1096             =head1 NAME
1097              
1098             IO::Uncompress::Unzip - Read zip files/buffers
1099              
1100             =head1 SYNOPSIS
1101              
1102             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1103              
1104             my $status = unzip $input => $output [,OPTS]
1105             or die "unzip failed: $UnzipError\n";
1106              
1107             my $z = IO::Uncompress::Unzip->new( $input [OPTS] )
1108             or die "unzip failed: $UnzipError\n";
1109              
1110             $status = $z->read($buffer)
1111             $status = $z->read($buffer, $length)
1112             $status = $z->read($buffer, $length, $offset)
1113             $line = $z->getline()
1114             $char = $z->getc()
1115             $char = $z->ungetc()
1116             $char = $z->opened()
1117              
1118             $status = $z->inflateSync()
1119              
1120             $data = $z->trailingData()
1121             $status = $z->nextStream()
1122             $data = $z->getHeaderInfo()
1123             $z->tell()
1124             $z->seek($position, $whence)
1125             $z->binmode()
1126             $z->fileno()
1127             $z->eof()
1128             $z->close()
1129              
1130             $UnzipError ;
1131              
1132             # IO::File mode
1133              
1134             <$z>
1135             read($z, $buffer);
1136             read($z, $buffer, $length);
1137             read($z, $buffer, $length, $offset);
1138             tell($z)
1139             seek($z, $position, $whence)
1140             binmode($z)
1141             fileno($z)
1142             eof($z)
1143             close($z)
1144              
1145             =head1 DESCRIPTION
1146              
1147             This module provides a Perl interface that allows the reading of
1148             zlib files/buffers.
1149              
1150             For writing zip files/buffers, see the companion module IO::Compress::Zip.
1151              
1152             The primary purpose of this module is to provide I<streaming> read access to
1153             zip files and buffers.
1154              
1155             At present the following compression methods are supported by IO::Uncompress::Unzip
1156              
1157             =over 5
1158              
1159             =item Store (0)
1160              
1161             =item Deflate (8)
1162              
1163             =item Bzip2 (12)
1164              
1165             To read Bzip2 content, the module C<IO::Uncompress::Bunzip2> must
1166             be installed.
1167              
1168             =item Lzma (14)
1169              
1170             To read LZMA content, the module C<IO::Uncompress::UnLzma> must
1171             be installed.
1172              
1173             =item Xz (95)
1174              
1175             To read Xz content, the module C<IO::Uncompress::UnXz> must
1176             be installed.
1177              
1178             =item Zstandard (93)
1179              
1180             To read Zstandard content, the module C<IO::Uncompress::UnZstd> must
1181             be installed.
1182              
1183             =back
1184              
1185             =head1 Functional Interface
1186              
1187             A top-level function, C<unzip>, is provided to carry out
1188             "one-shot" uncompression between buffers and/or files. For finer
1189             control over the uncompression process, see the L</"OO Interface">
1190             section.
1191              
1192             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1193              
1194             unzip $input_filename_or_reference => $output_filename_or_reference [,OPTS]
1195             or die "unzip failed: $UnzipError\n";
1196              
1197             The functional interface needs Perl5.005 or better.
1198              
1199             =head2 unzip $input_filename_or_reference => $output_filename_or_reference [, OPTS]
1200              
1201             C<unzip> expects at least two parameters,
1202             C<$input_filename_or_reference> and C<$output_filename_or_reference>
1203             and zero or more optional parameters (see L</Optional Parameters>)
1204              
1205             =head3 The C<$input_filename_or_reference> parameter
1206              
1207             The parameter, C<$input_filename_or_reference>, is used to define the
1208             source of the compressed data.
1209              
1210             It can take one of the following forms:
1211              
1212             =over 5
1213              
1214             =item A filename
1215              
1216             If the C<$input_filename_or_reference> parameter is a simple scalar, it is
1217             assumed to be a filename. This file will be opened for reading and the
1218             input data will be read from it.
1219              
1220             =item A filehandle
1221              
1222             If the C<$input_filename_or_reference> parameter is a filehandle, the input
1223             data will be read from it. The string '-' can be used as an alias for
1224             standard input.
1225              
1226             =item A scalar reference
1227              
1228             If C<$input_filename_or_reference> is a scalar reference, the input data
1229             will be read from C<$$input_filename_or_reference>.
1230              
1231             =item An array reference
1232              
1233             If C<$input_filename_or_reference> is an array reference, each element in
1234             the array must be a filename.
1235              
1236             The input data will be read from each file in turn.
1237              
1238             The complete array will be walked to ensure that it only
1239             contains valid filenames before any data is uncompressed.
1240              
1241             =item An Input FileGlob string
1242              
1243             If C<$input_filename_or_reference> is a string that is delimited by the
1244             characters "<" and ">" C<unzip> will assume that it is an
1245             I<input fileglob string>. The input is the list of files that match the
1246             fileglob.
1247              
1248             See L<File::GlobMapper|File::GlobMapper> for more details.
1249              
1250             =back
1251              
1252             If the C<$input_filename_or_reference> parameter is any other type,
1253             C<undef> will be returned.
1254              
1255             =head3 The C<$output_filename_or_reference> parameter
1256              
1257             The parameter C<$output_filename_or_reference> is used to control the
1258             destination of the uncompressed data. This parameter can take one of
1259             these forms.
1260              
1261             =over 5
1262              
1263             =item A filename
1264              
1265             If the C<$output_filename_or_reference> parameter is a simple scalar, it is
1266             assumed to be a filename. This file will be opened for writing and the
1267             uncompressed data will be written to it.
1268              
1269             =item A filehandle
1270              
1271             If the C<$output_filename_or_reference> parameter is a filehandle, the
1272             uncompressed data will be written to it. The string '-' can be used as
1273             an alias for standard output.
1274              
1275             =item A scalar reference
1276              
1277             If C<$output_filename_or_reference> is a scalar reference, the
1278             uncompressed data will be stored in C<$$output_filename_or_reference>.
1279              
1280             =item An Array Reference
1281              
1282             If C<$output_filename_or_reference> is an array reference,
1283             the uncompressed data will be pushed onto the array.
1284              
1285             =item An Output FileGlob
1286              
1287             If C<$output_filename_or_reference> is a string that is delimited by the
1288             characters "<" and ">" C<unzip> will assume that it is an
1289             I<output fileglob string>. The output is the list of files that match the
1290             fileglob.
1291              
1292             When C<$output_filename_or_reference> is an fileglob string,
1293             C<$input_filename_or_reference> must also be a fileglob string. Anything
1294             else is an error.
1295              
1296             See L<File::GlobMapper|File::GlobMapper> for more details.
1297              
1298             =back
1299              
1300             If the C<$output_filename_or_reference> parameter is any other type,
1301             C<undef> will be returned.
1302              
1303             =head2 Notes
1304              
1305             When C<$input_filename_or_reference> maps to multiple compressed
1306             files/buffers and C<$output_filename_or_reference> is
1307             a single file/buffer, after uncompression C<$output_filename_or_reference> will contain a
1308             concatenation of all the uncompressed data from each of the input
1309             files/buffers.
1310              
1311             =head2 Optional Parameters
1312              
1313             The optional parameters for the one-shot function C<unzip>
1314             are (for the most part) identical to those used with the OO interface defined in the
1315             L</"Constructor Options"> section. The exceptions are listed below
1316              
1317             =over 5
1318              
1319             =item C<< AutoClose => 0|1 >>
1320              
1321             This option applies to any input or output data streams to
1322             C<unzip> that are filehandles.
1323              
1324             If C<AutoClose> is specified, and the value is true, it will result in all
1325             input and/or output filehandles being closed once C<unzip> has
1326             completed.
1327              
1328             This parameter defaults to 0.
1329              
1330             =item C<< BinModeOut => 0|1 >>
1331              
1332             This option is now a no-op. All files will be written in binmode.
1333              
1334             =item C<< Append => 0|1 >>
1335              
1336             The behaviour of this option is dependent on the type of output data
1337             stream.
1338              
1339             =over 5
1340              
1341             =item * A Buffer
1342              
1343             If C<Append> is enabled, all uncompressed data will be append to the end of
1344             the output buffer. Otherwise the output buffer will be cleared before any
1345             uncompressed data is written to it.
1346              
1347             =item * A Filename
1348              
1349             If C<Append> is enabled, the file will be opened in append mode. Otherwise
1350             the contents of the file, if any, will be truncated before any uncompressed
1351             data is written to it.
1352              
1353             =item * A Filehandle
1354              
1355             If C<Append> is enabled, the filehandle will be positioned to the end of
1356             the file via a call to C<seek> before any uncompressed data is
1357             written to it. Otherwise the file pointer will not be moved.
1358              
1359             =back
1360              
1361             When C<Append> is specified, and set to true, it will I<append> all uncompressed
1362             data to the output data stream.
1363              
1364             So when the output is a filehandle it will carry out a seek to the eof
1365             before writing any uncompressed data. If the output is a filename, it will be opened for
1366             appending. If the output is a buffer, all uncompressed data will be
1367             appended to the existing buffer.
1368              
1369             Conversely when C<Append> is not specified, or it is present and is set to
1370             false, it will operate as follows.
1371              
1372             When the output is a filename, it will truncate the contents of the file
1373             before writing any uncompressed data. If the output is a filehandle
1374             its position will not be changed. If the output is a buffer, it will be
1375             wiped before any uncompressed data is output.
1376              
1377             Defaults to 0.
1378              
1379             =item C<< MultiStream => 0|1 >>
1380              
1381             If the input file/buffer contains multiple compressed data streams, this
1382             option will uncompress the whole lot as a single data stream.
1383              
1384             Defaults to 0.
1385              
1386             =item C<< TrailingData => $scalar >>
1387              
1388             Returns the data, if any, that is present immediately after the compressed
1389             data stream once uncompression is complete.
1390              
1391             This option can be used when there is useful information immediately
1392             following the compressed data stream, and you don't know the length of the
1393             compressed data stream.
1394              
1395             If the input is a buffer, C<trailingData> will return everything from the
1396             end of the compressed data stream to the end of the buffer.
1397              
1398             If the input is a filehandle, C<trailingData> will return the data that is
1399             left in the filehandle input buffer once the end of the compressed data
1400             stream has been reached. You can then use the filehandle to read the rest
1401             of the input file.
1402              
1403             Don't bother using C<trailingData> if the input is a filename.
1404              
1405             If you know the length of the compressed data stream before you start
1406             uncompressing, you can avoid having to use C<trailingData> by setting the
1407             C<InputLength> option.
1408              
1409             =back
1410              
1411             =head2 OneShot Examples
1412              
1413             Say you have a zip file, C<file1.zip>, that only contains a
1414             single member, you can read it and write the uncompressed data to the
1415             file C<file1.txt> like this.
1416              
1417             use strict ;
1418             use warnings ;
1419             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1420              
1421             my $input = "file1.zip";
1422             my $output = "file1.txt";
1423             unzip $input => $output
1424             or die "unzip failed: $UnzipError\n";
1425              
1426             If you have a zip file that contains multiple members and want to read a
1427             specific member from the file, say C<"data1">, use the C<Name> option
1428              
1429             use strict ;
1430             use warnings ;
1431             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1432              
1433             my $input = "file1.zip";
1434             my $output = "file1.txt";
1435             unzip $input => $output, Name => "data1"
1436             or die "unzip failed: $UnzipError\n";
1437              
1438             Alternatively, if you want to read the C<"data1"> member into memory, use
1439             a scalar reference for the C<output> parameter.
1440              
1441             use strict ;
1442             use warnings ;
1443             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1444              
1445             my $input = "file1.zip";
1446             my $output ;
1447             unzip $input => \$output, Name => "data1"
1448             or die "unzip failed: $UnzipError\n";
1449             # $output now contains the uncompressed data
1450              
1451             To read from an existing Perl filehandle, C<$input>, and write the
1452             uncompressed data to a buffer, C<$buffer>.
1453              
1454             use strict ;
1455             use warnings ;
1456             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1457             use IO::File ;
1458              
1459             my $input = IO::File->new( "<file1.zip" )
1460             or die "Cannot open 'file1.zip': $!\n" ;
1461             my $buffer ;
1462             unzip $input => \$buffer
1463             or die "unzip failed: $UnzipError\n";
1464              
1465             =head1 OO Interface
1466              
1467             =head2 Constructor
1468              
1469             The format of the constructor for IO::Uncompress::Unzip is shown below
1470              
1471             my $z = IO::Uncompress::Unzip->new( $input [OPTS] )
1472             or die "IO::Uncompress::Unzip failed: $UnzipError\n";
1473              
1474             The constructor takes one mandatory parameter, C<$input>, defined below, and
1475             zero or more C<OPTS>, defined in L<Constructor Options>.
1476              
1477             Returns an C<IO::Uncompress::Unzip> object on success and undef on failure.
1478             The variable C<$UnzipError> will contain an error message on failure.
1479              
1480             If you are running Perl 5.005 or better the object, C<$z>, returned from
1481             IO::Uncompress::Unzip can be used exactly like an L<IO::File|IO::File> filehandle.
1482             This means that all normal input file operations can be carried out with
1483             C<$z>. For example, to read a line from a compressed file/buffer you can
1484             use either of these forms
1485              
1486             $line = $z->getline();
1487             $line = <$z>;
1488              
1489             Below is a simple exaple of using the OO interface to read the compressed file
1490             C<myfile.zip> and write its contents to stdout.
1491              
1492             my $filename = "myfile.zip";
1493             my $z = IO::Uncompress::Unzip->new($filename)
1494             or die "IO::Uncompress::Unzip failed: $UnzipError\n";
1495              
1496             while (<$z>) {
1497             print $_;
1498             }
1499             $z->close();
1500              
1501             See L</EXAMPLES> for further examples
1502              
1503             The mandatory parameter C<$input> is used to determine the source of the
1504             compressed data. This parameter can take one of three forms.
1505              
1506             =over 5
1507              
1508             =item A filename
1509              
1510             If the C<$input> parameter is a scalar, it is assumed to be a filename. This
1511             file will be opened for reading and the compressed data will be read from it.
1512              
1513             =item A filehandle
1514              
1515             If the C<$input> parameter is a filehandle, the compressed data will be
1516             read from it.
1517             The string '-' can be used as an alias for standard input.
1518              
1519             =item A scalar reference
1520              
1521             If C<$input> is a scalar reference, the compressed data will be read from
1522             C<$$input>.
1523              
1524             =back
1525              
1526             =head2 Constructor Options
1527              
1528             The option names defined below are case insensitive and can be optionally
1529             prefixed by a '-'. So all of the following are valid
1530              
1531             -AutoClose
1532             -autoclose
1533             AUTOCLOSE
1534             autoclose
1535              
1536             OPTS is a combination of the following options:
1537              
1538             =over 5
1539              
1540             =item C<< Name => "membername" >>
1541              
1542             Open "membername" from the zip file for reading.
1543              
1544             =item C<< Efs => 0| 1 >>
1545              
1546             When this option is set to true AND the zip archive being read has
1547             the "Language Encoding Flag" (EFS) set, the member name is assumed to be encoded in UTF-8.
1548              
1549             If the member name in the zip archive is not valid UTF-8 when this optionn is true,
1550             the script will die with an error message.
1551              
1552             Note that this option only works with Perl 5.8.4 or better.
1553              
1554             This option defaults to B<false>.
1555              
1556             =item C<< AutoClose => 0|1 >>
1557              
1558             This option is only valid when the C<$input> parameter is a filehandle. If
1559             specified, and the value is true, it will result in the file being closed once
1560             either the C<close> method is called or the IO::Uncompress::Unzip object is
1561             destroyed.
1562              
1563             This parameter defaults to 0.
1564              
1565             =item C<< MultiStream => 0|1 >>
1566              
1567             Treats the complete zip file/buffer as a single compressed data
1568             stream. When reading in multi-stream mode each member of the zip
1569             file/buffer will be uncompressed in turn until the end of the file/buffer
1570             is encountered.
1571              
1572             This parameter defaults to 0.
1573              
1574             =item C<< Prime => $string >>
1575              
1576             This option will uncompress the contents of C<$string> before processing the
1577             input file/buffer.
1578              
1579             This option can be useful when the compressed data is embedded in another
1580             file/data structure and it is not possible to work out where the compressed
1581             data begins without having to read the first few bytes. If this is the
1582             case, the uncompression can be I<primed> with these bytes using this
1583             option.
1584              
1585             =item C<< Transparent => 0|1 >>
1586              
1587             If this option is set and the input file/buffer is not compressed data,
1588             the module will allow reading of it anyway.
1589              
1590             In addition, if the input file/buffer does contain compressed data and
1591             there is non-compressed data immediately following it, setting this option
1592             will make this module treat the whole file/buffer as a single data stream.
1593              
1594             This option defaults to 1.
1595              
1596             =item C<< BlockSize => $num >>
1597              
1598             When reading the compressed input data, IO::Uncompress::Unzip will read it in
1599             blocks of C<$num> bytes.
1600              
1601             This option defaults to 4096.
1602              
1603             =item C<< InputLength => $size >>
1604              
1605             When present this option will limit the number of compressed bytes read
1606             from the input file/buffer to C<$size>. This option can be used in the
1607             situation where there is useful data directly after the compressed data
1608             stream and you know beforehand the exact length of the compressed data
1609             stream.
1610              
1611             This option is mostly used when reading from a filehandle, in which case
1612             the file pointer will be left pointing to the first byte directly after the
1613             compressed data stream.
1614              
1615             This option defaults to off.
1616              
1617             =item C<< Append => 0|1 >>
1618              
1619             This option controls what the C<read> method does with uncompressed data.
1620              
1621             If set to 1, all uncompressed data will be appended to the output parameter
1622             of the C<read> method.
1623              
1624             If set to 0, the contents of the output parameter of the C<read> method
1625             will be overwritten by the uncompressed data.
1626              
1627             Defaults to 0.
1628              
1629             =item C<< Strict => 0|1 >>
1630              
1631             This option controls whether the extra checks defined below are used when
1632             carrying out the decompression. When Strict is on, the extra tests are
1633             carried out, when Strict is off they are not.
1634              
1635             The default for this option is off.
1636              
1637             =back
1638              
1639             =head1 Methods
1640              
1641             =head2 read
1642              
1643             Usage is
1644              
1645             $status = $z->read($buffer)
1646              
1647             Reads a block of compressed data (the size of the compressed block is
1648             determined by the C<Buffer> option in the constructor), uncompresses it and
1649             writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
1650             set in the constructor, the uncompressed data will be appended to the
1651             C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
1652              
1653             Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
1654             or a negative number on error.
1655              
1656             =head2 read
1657              
1658             Usage is
1659              
1660             $status = $z->read($buffer, $length)
1661             $status = $z->read($buffer, $length, $offset)
1662              
1663             $status = read($z, $buffer, $length)
1664             $status = read($z, $buffer, $length, $offset)
1665              
1666             Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
1667              
1668             The main difference between this form of the C<read> method and the
1669             previous one, is that this one will attempt to return I<exactly> C<$length>
1670             bytes. The only circumstances that this function will not is if end-of-file
1671             or an IO error is encountered.
1672              
1673             Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
1674             or a negative number on error.
1675              
1676             =head2 getline
1677              
1678             Usage is
1679              
1680             $line = $z->getline()
1681             $line = <$z>
1682              
1683             Reads a single line.
1684              
1685             This method fully supports the use of the variable C<$/> (or
1686             C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
1687             determine what constitutes an end of line. Paragraph mode, record mode and
1688             file slurp mode are all supported.
1689              
1690             =head2 getc
1691              
1692             Usage is
1693              
1694             $char = $z->getc()
1695              
1696             Read a single character.
1697              
1698             =head2 ungetc
1699              
1700             Usage is
1701              
1702             $char = $z->ungetc($string)
1703              
1704             =head2 inflateSync
1705              
1706             Usage is
1707              
1708             $status = $z->inflateSync()
1709              
1710             TODO
1711              
1712             =head2 getHeaderInfo
1713              
1714             Usage is
1715              
1716             $hdr = $z->getHeaderInfo();
1717             @hdrs = $z->getHeaderInfo();
1718              
1719             This method returns either a hash reference (in scalar context) or a list
1720             or hash references (in array context) that contains information about each
1721             of the header fields in the compressed data stream(s).
1722              
1723             =head2 tell
1724              
1725             Usage is
1726              
1727             $z->tell()
1728             tell $z
1729              
1730             Returns the uncompressed file offset.
1731              
1732             =head2 eof
1733              
1734             Usage is
1735              
1736             $z->eof();
1737             eof($z);
1738              
1739             Returns true if the end of the compressed input stream has been reached.
1740              
1741             =head2 seek
1742              
1743             $z->seek($position, $whence);
1744             seek($z, $position, $whence);
1745              
1746             Provides a sub-set of the C<seek> functionality, with the restriction
1747             that it is only legal to seek forward in the input file/buffer.
1748             It is a fatal error to attempt to seek backward.
1749              
1750             Note that the implementation of C<seek> in this module does not provide
1751             true random access to a compressed file/buffer. It works by uncompressing
1752             data from the current offset in the file/buffer until it reaches the
1753             uncompressed offset specified in the parameters to C<seek>. For very small
1754             files this may be acceptable behaviour. For large files it may cause an
1755             unacceptable delay.
1756              
1757             The C<$whence> parameter takes one the usual values, namely SEEK_SET,
1758             SEEK_CUR or SEEK_END.
1759              
1760             Returns 1 on success, 0 on failure.
1761              
1762             =head2 binmode
1763              
1764             Usage is
1765              
1766             $z->binmode
1767             binmode $z ;
1768              
1769             This is a noop provided for completeness.
1770              
1771             =head2 opened
1772              
1773             $z->opened()
1774              
1775             Returns true if the object currently refers to a opened file/buffer.
1776              
1777             =head2 autoflush
1778              
1779             my $prev = $z->autoflush()
1780             my $prev = $z->autoflush(EXPR)
1781              
1782             If the C<$z> object is associated with a file or a filehandle, this method
1783             returns the current autoflush setting for the underlying filehandle. If
1784             C<EXPR> is present, and is non-zero, it will enable flushing after every
1785             write/print operation.
1786              
1787             If C<$z> is associated with a buffer, this method has no effect and always
1788             returns C<undef>.
1789              
1790             B<Note> that the special variable C<$|> B<cannot> be used to set or
1791             retrieve the autoflush setting.
1792              
1793             =head2 input_line_number
1794              
1795             $z->input_line_number()
1796             $z->input_line_number(EXPR)
1797              
1798             Returns the current uncompressed line number. If C<EXPR> is present it has
1799             the effect of setting the line number. Note that setting the line number
1800             does not change the current position within the file/buffer being read.
1801              
1802             The contents of C<$/> are used to determine what constitutes a line
1803             terminator.
1804              
1805             =head2 fileno
1806              
1807             $z->fileno()
1808             fileno($z)
1809              
1810             If the C<$z> object is associated with a file or a filehandle, C<fileno>
1811             will return the underlying file descriptor. Once the C<close> method is
1812             called C<fileno> will return C<undef>.
1813              
1814             If the C<$z> object is associated with a buffer, this method will return
1815             C<undef>.
1816              
1817             =head2 close
1818              
1819             $z->close() ;
1820             close $z ;
1821              
1822             Closes the output file/buffer.
1823              
1824             For most versions of Perl this method will be automatically invoked if
1825             the IO::Uncompress::Unzip object is destroyed (either explicitly or by the
1826             variable with the reference to the object going out of scope). The
1827             exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1828             these cases, the C<close> method will be called automatically, but
1829             not until global destruction of all live objects when the program is
1830             terminating.
1831              
1832             Therefore, if you want your scripts to be able to run on all versions
1833             of Perl, you should call C<close> explicitly and not rely on automatic
1834             closing.
1835              
1836             Returns true on success, otherwise 0.
1837              
1838             If the C<AutoClose> option has been enabled when the IO::Uncompress::Unzip
1839             object was created, and the object is associated with a file, the
1840             underlying file will also be closed.
1841              
1842             =head2 nextStream
1843              
1844             Usage is
1845              
1846             my $status = $z->nextStream();
1847              
1848             Skips to the next compressed data stream in the input file/buffer. If a new
1849             compressed data stream is found, the eof marker will be cleared and C<$.>
1850             will be reset to 0.
1851              
1852             If trailing data is present immediately after the zip archive and the
1853             C<Transparent> option is enabled, this method will consider that trailing
1854             data to be another member of the zip archive.
1855              
1856             Returns 1 if a new stream was found, 0 if none was found, and -1 if an
1857             error was encountered.
1858              
1859             =head2 trailingData
1860              
1861             Usage is
1862              
1863             my $data = $z->trailingData();
1864              
1865             Returns the data, if any, that is present immediately after the compressed
1866             data stream once uncompression is complete. It only makes sense to call
1867             this method once the end of the compressed data stream has been
1868             encountered.
1869              
1870             This option can be used when there is useful information immediately
1871             following the compressed data stream, and you don't know the length of the
1872             compressed data stream.
1873              
1874             If the input is a buffer, C<trailingData> will return everything from the
1875             end of the compressed data stream to the end of the buffer.
1876              
1877             If the input is a filehandle, C<trailingData> will return the data that is
1878             left in the filehandle input buffer once the end of the compressed data
1879             stream has been reached. You can then use the filehandle to read the rest
1880             of the input file.
1881              
1882             Don't bother using C<trailingData> if the input is a filename.
1883              
1884             If you know the length of the compressed data stream before you start
1885             uncompressing, you can avoid having to use C<trailingData> by setting the
1886             C<InputLength> option in the constructor.
1887              
1888             =head1 Importing
1889              
1890             No symbolic constants are required by IO::Uncompress::Unzip at present.
1891              
1892             =over 5
1893              
1894             =item :all
1895              
1896             Imports C<unzip> and C<$UnzipError>.
1897             Same as doing this
1898              
1899             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1900              
1901             =back
1902              
1903             =head1 EXAMPLES
1904              
1905             =head2 Simple Read
1906              
1907             Say you have a zip file, C<file1.zip>, that only contains a
1908             single member, you can read it and write the uncompressed data to the
1909             file C<file1.txt> like this.
1910              
1911             use strict ;
1912             use warnings ;
1913             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1914              
1915             my $filename = "file1.zip";
1916             my $z = IO::Uncompress::Unzip->new($filename)
1917             or die "IO::Uncompress::Unzip failed: $UnzipError\n";
1918             open my $out, ">", "file1.txt";
1919              
1920             while (<$z>) {
1921             print $out $_;
1922             }
1923             $z->close();
1924              
1925             If you have a zip file that contains multiple members and want to read a
1926             specific member from the file, say C<"data1">, use the C<Name> option when
1927             constructing the
1928              
1929             use strict ;
1930             use warnings ;
1931             use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1932              
1933             my $filename = "file1.zip";
1934             my $z = IO::Uncompress::Unzip->new($filename, Name => "data1")
1935             or die "IO::Uncompress::Unzip failed: $UnzipError\n";
1936              
1937             =head2 Walking through a zip file
1938              
1939             The code below can be used to traverse a zip file, one compressed data
1940             stream at a time.
1941              
1942             use IO::Uncompress::Unzip qw($UnzipError);
1943              
1944             my $zipfile = "somefile.zip";
1945             my $u = IO::Uncompress::Unzip->new( $zipfile )
1946             or die "Cannot open $zipfile: $UnzipError";
1947              
1948             my $status;
1949             for ($status = 1; $status > 0; $status = $u->nextStream())
1950             {
1951              
1952             my $name = $u->getHeaderInfo()->{Name};
1953             warn "Processing member $name\n" ;
1954              
1955             my $buff;
1956             while (($status = $u->read($buff)) > 0) {
1957             # Do something here
1958             }
1959              
1960             last if $status < 0;
1961             }
1962              
1963             die "Error processing $zipfile: $!\n"
1964             if $status < 0 ;
1965              
1966             Each individual compressed data stream is read until the logical
1967             end-of-file is reached. Then C<nextStream> is called. This will skip to the
1968             start of the next compressed data stream and clear the end-of-file flag.
1969              
1970             It is also worth noting that C<nextStream> can be called at any time -- you
1971             don't have to wait until you have exhausted a compressed data stream before
1972             skipping to the next one.
1973              
1974             =head2 Unzipping a complete zip file to disk
1975              
1976             Daniel S. Sterling has written a script that uses C<IO::Uncompress::UnZip>
1977             to read a zip file and unzip its contents to disk.
1978              
1979             The script is available from L<https://gist.github.com/eqhmcow/5389877>
1980              
1981             =head2 Working with Net::FTP
1982              
1983             See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
1984              
1985             =head1 SUPPORT
1986              
1987             General feedback/questions/bug reports should be sent to
1988             L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
1989             L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
1990              
1991             =head1 SEE ALSO
1992              
1993             L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1994              
1995             L<IO::Compress::FAQ|IO::Compress::FAQ>
1996              
1997             L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1998             L<Archive::Tar|Archive::Tar>,
1999             L<IO::Zlib|IO::Zlib>
2000              
2001             For RFC 1950, 1951 and 1952 see
2002             L<https://datatracker.ietf.org/doc/html/rfc1950>,
2003             L<https://datatracker.ietf.org/doc/html/rfc1951> and
2004             L<https://datatracker.ietf.org/doc/html/rfc1952>
2005              
2006             The I<zlib> compression library was written by Jean-loup Gailly
2007             C<gzip@prep.ai.mit.edu> and Mark Adler C<madler@alumni.caltech.edu>.
2008              
2009             The primary site for the I<zlib> compression library is
2010             L<http://www.zlib.org>.
2011              
2012             The primary site for the I<zlib-ng> compression library is
2013             L<https://github.com/zlib-ng/zlib-ng>.
2014              
2015             The primary site for gzip is L<http://www.gzip.org>.
2016              
2017             =head1 AUTHOR
2018              
2019             This module was written by Paul Marquess, C<pmqs@cpan.org>.
2020              
2021             =head1 MODIFICATION HISTORY
2022              
2023             See the Changes file.
2024              
2025             =head1 COPYRIGHT AND LICENSE
2026              
2027             Copyright (c) 2005-2026 Paul Marquess. All rights reserved.
2028              
2029             This program is free software; you can redistribute it and/or
2030             modify it under the same terms as Perl itself.