1 package IO::Uncompress::Unzip;
11 use IO::Uncompress::RawInflate ;
12 use IO::Compress::Base::Common qw(:Status createSelfTiedObject);
13 use IO::Uncompress::Adapter::Identity;
15 use Compress::Raw::Zlib qw(crc32) ;
18 eval { require IO::Uncompress::Adapter::Bunzip2 ;
19 import IO::Uncompress::Adapter::Bunzip2 } ;
25 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $UnzipError);
27 $VERSION = '2.000_11';
30 @ISA = qw(Exporter IO::Uncompress::RawInflate);
31 @EXPORT_OK = qw( $UnzipError unzip );
32 %EXPORT_TAGS = %IO::Uncompress::RawInflate::EXPORT_TAGS ;
33 push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
34 Exporter::export_ok_tags('all');
40 my $obj = createSelfTiedObject($class, \$UnzipError);
41 $obj->_create(undef, 0, @_);
46 my $obj = createSelfTiedObject(undef, \$UnzipError);
47 return $obj->_inf(@_) ;
52 use IO::Compress::Base::Common qw(:Parse);
57 'Name' => [1, 1, Parse_any, undef],
59 # 'Streaming' => [1, 1, Parse_boolean, 1],
68 # unzip always needs crc32
69 $got->value('CRC32' => 1);
71 *$self->{UnzipData}{Name} = $got->value('Name');
82 $self->smartReadExact(\$magic, 4);
84 *$self->{HeaderPending} = $magic ;
86 return $self->HeaderError("Minimum header size is " .
88 if length $magic != 4 ;
90 return $self->HeaderError("Bad Magic")
91 if ! _isZipMagic($magic) ;
93 *$self->{Type} = 'zip';
105 my $name = *$self->{UnzipData}{Name} ;
106 my $hdr = $self->_readZipHeader($magic) ;
110 if (! defined $name || $hdr->{Name} eq $name)
117 if (*$self->{ZipData}{Streaming}) {
122 my $status = $self->smartRead(\$b, 1024 * 16);
128 $status = *$self->{Uncomp}->uncompr(\$b, \$temp_buf, 0, $out);
130 return $self->saveErrorString(undef, *$self->{Uncomp}{Error},
131 *$self->{Uncomp}{ErrorNo})
132 if $self->saveStatus($status) == STATUS_ERROR;
134 if ($status == STATUS_ENDSTREAM) {
135 *$self->{Uncomp}->reset();
136 $self->pushBack($b) ;
142 $self->smartReadExact(\$buffer, $hdr->{TrailerLength})
143 or return $self->saveErrorString(undef, "Truncated file");
146 my $c = $hdr->{CompressedLength};
147 $self->smartReadExact(\$buffer, $c)
148 or return $self->saveErrorString(undef, "Truncated file");
152 $self->chkTrailer($buffer) == STATUS_OK
153 or return $self->saveErrorString(undef, "Truncated file");
155 $hdr = $self->_readFullZipHeader();
157 return $self->saveErrorString(undef, "Cannot find '$name'")
158 if $self->smartEof();
169 my ($sig, $CRC32, $cSize, $uSize) ;
170 if (*$self->{ZipData}{Streaming}) {
171 ($sig, $CRC32, $cSize, $uSize) = unpack("V V V V", $trailer) ;
172 return $self->TrailerError("Data Descriptor signature, got $sig")
173 if $sig != 0x08074b50;
176 ($CRC32, $cSize, $uSize) =
177 (*$self->{ZipData}{Crc32},
178 *$self->{ZipData}{CompressedLen},
179 *$self->{ZipData}{UnCompressedLen});
182 if (*$self->{Strict}) {
183 return $self->TrailerError("CRC mismatch")
184 if $CRC32 != *$self->{ZipData}{CRC32} ;
186 my $exp_isize = *$self->{Uncomp}->compressedBytes();
187 return $self->TrailerError("CSIZE mismatch. Got $cSize"
188 . ", expected $exp_isize")
189 if $cSize != $exp_isize ;
191 $exp_isize = *$self->{Uncomp}->uncompressedBytes();
192 return $self->TrailerError("USIZE mismatch. Got $uSize"
193 . ", expected $exp_isize")
194 if $uSize != $exp_isize ;
197 my $reachedEnd = STATUS_ERROR ;
198 # check for central directory or end of central directory
202 my $got = $self->smartRead(\$magic, 4);
204 return $self->saveErrorString(STATUS_ERROR, "Truncated file")
205 if $got != 4 && *$self->{Strict};
211 return STATUS_ERROR ;
214 $self->pushBack($magic) ;
218 my $sig = unpack("V", $magic) ;
220 if ($sig == 0x02014b50)
222 if ($self->skipCentralDirectory($magic) != STATUS_OK ) {
223 if (*$self->{Strict}) {
224 return STATUS_ERROR ;
232 elsif ($sig == 0x06054b50)
234 if ($self->skipEndCentralDirectory($magic) != STATUS_OK) {
235 if (*$self->{Strict}) {
236 return STATUS_ERROR ;
243 # $reachedEnd = STATUS_OK ;
247 elsif ($sig == 0x04034b50)
249 $self->pushBack($magic) ;
255 $self->pushBack($magic) ;
263 sub skipCentralDirectory
269 $self->smartReadExact(\$buffer, 46 - 4)
270 or return $self->TrailerError("Minimum header size is " .
273 my $keep = $magic . $buffer ;
274 *$self->{HeaderPending} = $keep ;
276 #my $versionMadeBy = unpack ("v", substr($buffer, 4-4, 2));
277 #my $extractVersion = unpack ("v", substr($buffer, 6-4, 2));
278 #my $gpFlag = unpack ("v", substr($buffer, 8-4, 2));
279 #my $compressedMethod = unpack ("v", substr($buffer, 10-4, 2));
280 #my $lastModTime = unpack ("V", substr($buffer, 12-4, 4));
281 #my $crc32 = unpack ("V", substr($buffer, 16-4, 4));
282 #my $compressedLength = unpack ("V", substr($buffer, 20-4, 4));
283 #my $uncompressedLength = unpack ("V", substr($buffer, 24-4, 4));
284 my $filename_length = unpack ("v", substr($buffer, 28-4, 2));
285 my $extra_length = unpack ("v", substr($buffer, 30-4, 2));
286 my $comment_length = unpack ("v", substr($buffer, 32-4, 2));
287 #my $disk_start = unpack ("v", substr($buffer, 34-4, 2));
288 #my $int_file_attrib = unpack ("v", substr($buffer, 36-4, 2));
289 #my $ext_file_attrib = unpack ("V", substr($buffer, 38-4, 2));
290 #my $lcl_hdr_offset = unpack ("V", substr($buffer, 42-4, 2));
296 if ($filename_length)
298 $self->smartReadExact(\$filename, $filename_length)
299 or return $self->TruncatedTrailer("filename");
305 $self->smartReadExact(\$extraField, $extra_length)
306 or return $self->TruncatedTrailer("extra");
307 $keep .= $extraField ;
312 $self->smartReadExact(\$comment, $comment_length)
313 or return $self->TruncatedTrailer("comment");
320 sub skipEndCentralDirectory
326 $self->smartReadExact(\$buffer, 22 - 4)
327 or return $self->TrailerError("Minimum header size is " .
330 my $keep = $magic . $buffer ;
331 *$self->{HeaderPending} = $keep ;
333 #my $diskNumber = unpack ("v", substr($buffer, 4-4, 2));
334 #my $cntrlDirDiskNo = unpack ("v", substr($buffer, 6-4, 2));
335 #my $entriesInThisCD = unpack ("v", substr($buffer, 8-4, 2));
336 #my $entriesInCD = unpack ("v", substr($buffer, 10-4, 2));
337 #my $sizeOfCD = unpack ("V", substr($buffer, 12-4, 2));
338 #my $offsetToCD = unpack ("V", substr($buffer, 16-4, 2));
339 my $comment_length = unpack ("v", substr($buffer, 20-4, 2));
345 $self->smartReadExact(\$comment, $comment_length)
346 or return $self->TruncatedTrailer("comment");
359 return 0 if length $buffer < 4 ;
360 my $sig = unpack("V", $buffer) ;
361 return $sig == 0x04034b50 ;
365 sub _readFullZipHeader($)
370 $self->smartReadExact(\$magic, 4);
372 *$self->{HeaderPending} = $magic ;
374 return $self->HeaderError("Minimum header size is " .
376 if length $magic != 4 ;
379 return $self->HeaderError("Bad Magic")
380 if ! _isZipMagic($magic) ;
382 my $status = $self->_readZipHeader($magic);
383 delete *$self->{Transparent} if ! defined $status ;
387 sub _readZipHeader($)
389 my ($self, $magic) = @_ ;
393 $self->smartReadExact(\$buffer, 30 - 4)
394 or return $self->HeaderError("Minimum header size is " .
397 my $keep = $magic . $buffer ;
398 *$self->{HeaderPending} = $keep ;
400 my $extractVersion = unpack ("v", substr($buffer, 4-4, 2));
401 my $gpFlag = unpack ("v", substr($buffer, 6-4, 2));
402 my $compressedMethod = unpack ("v", substr($buffer, 8-4, 2));
403 my $lastModTime = unpack ("V", substr($buffer, 10-4, 4));
404 my $crc32 = unpack ("V", substr($buffer, 14-4, 4));
405 my $compressedLength = unpack ("V", substr($buffer, 18-4, 4));
406 my $uncompressedLength = unpack ("V", substr($buffer, 22-4, 4));
407 my $filename_length = unpack ("v", substr($buffer, 26-4, 2));
408 my $extra_length = unpack ("v", substr($buffer, 28-4, 2));
412 my $streamingMode = ($gpFlag & 0x08) ? 1 : 0 ;
414 return $self->HeaderError("Streamed Stored content not supported")
415 if $streamingMode && $compressedMethod == 0 ;
417 *$self->{ZipData}{Streaming} = $streamingMode;
419 if (! $streamingMode) {
420 *$self->{ZipData}{Streaming} = 0;
421 *$self->{ZipData}{Crc32} = $crc32;
422 *$self->{ZipData}{CompressedLen} = $compressedLength;
423 *$self->{ZipData}{UnCompressedLen} = $uncompressedLength;
424 *$self->{CompressedInputLengthRemaining} =
425 *$self->{CompressedInputLength} = $compressedLength;
429 if ($filename_length)
431 $self->smartReadExact(\$filename, $filename_length)
432 or return $self->HeaderError("xxx");
438 $self->smartReadExact(\$extraField, $extra_length)
439 or return $self->HeaderError("xxx");
440 $keep .= $extraField ;
443 *$self->{ZipData}{Method} = $compressedMethod;
444 if ($compressedMethod == 8)
446 *$self->{Type} = 'zip-deflate';
448 elsif ($compressedMethod == 12)
450 #if (! defined $IO::Uncompress::Adapter::Bunzip2::VERSION)
452 *$self->{Type} = 'zip-bzip2';
454 my $obj = IO::Uncompress::Adapter::Bunzip2::mkUncompObject(
457 *$self->{Uncomp} = $obj;
458 *$self->{ZipData}{CRC32} = crc32(undef);
461 elsif ($compressedMethod == 0)
463 # TODO -- add support for reading uncompressed
465 *$self->{Type} = 'zip-stored';
467 my $obj = IO::Uncompress::Adapter::Identity::mkUncompObject(# $got->value('CRC32'),
468 # $got->value('ADLER32'),
471 *$self->{Uncomp} = $obj;
476 return $self->HeaderError("Unsupported Compression format $compressedMethod");
481 'FingerprintLength' => 4,
482 #'HeaderLength' => $compressedMethod == 8 ? length $keep : 0,
483 'HeaderLength' => length $keep,
484 'TrailerLength' => $streamingMode ? 16 : 0,
486 'CompressedLength' => $compressedLength ,
487 'UncompressedLength' => $uncompressedLength ,
490 'Time' => _dosToUnixTime($lastModTime),
491 'Stream' => $streamingMode,
493 'MethodID' => $compressedMethod,
494 'MethodName' => $compressedMethod == 8
496 : $compressedMethod == 0
500 # 'TextFlag' => $flag & GZIP_FLG_FTEXT ? 1 : 0,
501 # 'HeaderCRCFlag' => $flag & GZIP_FLG_FHCRC ? 1 : 0,
502 # 'NameFlag' => $flag & GZIP_FLG_FNAME ? 1 : 0,
503 # 'CommentFlag' => $flag & GZIP_FLG_FCOMMENT ? 1 : 0,
504 # 'ExtraFlag' => $flag & GZIP_FLG_FEXTRA ? 1 : 0,
505 # 'Comment' => $comment,
507 # 'OsName' => defined $GZIP_OS_Names{$os}
508 # ? $GZIP_OS_Names{$os} : "Unknown",
509 # 'HeaderCRC' => $HeaderCRC,
511 # 'ExtraFlags' => $xfl,
512 # 'ExtraFieldRaw' => $EXTRA,
513 # 'ExtraField' => [ @EXTRA ],
519 sub filterUncompressed
523 if (*$self->{ZipData}{Method} == 12) {
524 *$self->{ZipData}{CRC32} = crc32(${$_[0]}, *$self->{ZipData}{CRC32});
527 *$self->{ZipData}{CRC32} = *$self->{Uncomp}->crc32() ;
535 #use Time::Local 'timelocal_nocheck';
536 use Time::Local 'timelocal';
540 my $year = ( ( $dt >> 25 ) & 0x7f ) + 80;
541 my $mon = ( ( $dt >> 21 ) & 0x0f ) - 1;
542 my $mday = ( ( $dt >> 16 ) & 0x1f );
544 my $hour = ( ( $dt >> 11 ) & 0x1f );
545 my $min = ( ( $dt >> 5 ) & 0x3f );
546 my $sec = ( ( $dt << 1 ) & 0x3e );
550 eval { timelocal( $sec, $min, $hour, $mday, $mon, $year ); };
566 IO::Uncompress::Unzip - Read zip files/buffers
572 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
574 my $status = unzip $input => $output [,OPTS]
575 or die "unzip failed: $UnzipError\n";
577 my $z = new IO::Uncompress::Unzip $input [OPTS]
578 or die "unzip failed: $UnzipError\n";
580 $status = $z->read($buffer)
581 $status = $z->read($buffer, $length)
582 $status = $z->read($buffer, $length, $offset)
583 $line = $z->getline()
588 $status = $z->inflateSync()
591 $data = $z->getHeaderInfo()
593 $z->seek($position, $whence)
605 read($z, $buffer, $length);
606 read($z, $buffer, $length, $offset);
608 seek($z, $position, $whence)
619 B<WARNING -- This is a Beta release>.
623 =item * DO NOT use in production code.
625 =item * The documentation is incomplete in places.
627 =item * Parts of the interface defined here are tentative.
629 =item * Please report any problems you find.
637 This module provides a Perl interface that allows the reading of
640 For writing zip files/buffers, see the companion module IO::Compress::Zip.
647 =head1 Functional Interface
649 A top-level function, C<unzip>, is provided to carry out
650 "one-shot" uncompression between buffers and/or files. For finer
651 control over the uncompression process, see the L</"OO Interface">
654 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
656 unzip $input => $output [,OPTS]
657 or die "unzip failed: $UnzipError\n";
661 The functional interface needs Perl5.005 or better.
664 =head2 unzip $input => $output [, OPTS]
667 C<unzip> expects at least two parameters, C<$input> and C<$output>.
669 =head3 The C<$input> parameter
671 The parameter, C<$input>, is used to define the source of
674 It can take one of the following forms:
680 If the C<$input> parameter is a simple scalar, it is assumed to be a
681 filename. This file will be opened for reading and the input data
682 will be read from it.
686 If the C<$input> parameter is a filehandle, the input data will be
688 The string '-' can be used as an alias for standard input.
690 =item A scalar reference
692 If C<$input> is a scalar reference, the input data will be read
695 =item An array reference
697 If C<$input> is an array reference, each element in the array must be a
700 The input data will be read from each file in turn.
702 The complete array will be walked to ensure that it only
703 contains valid filenames before any data is uncompressed.
707 =item An Input FileGlob string
709 If C<$input> is a string that is delimited by the characters "<" and ">"
710 C<unzip> will assume that it is an I<input fileglob string>. The
711 input is the list of files that match the fileglob.
713 If the fileglob does not match any files ...
715 See L<File::GlobMapper|File::GlobMapper> for more details.
720 If the C<$input> parameter is any other type, C<undef> will be returned.
724 =head3 The C<$output> parameter
726 The parameter C<$output> is used to control the destination of the
727 uncompressed data. This parameter can take one of these forms.
733 If the C<$output> parameter is a simple scalar, it is assumed to be a
734 filename. This file will be opened for writing and the uncompressed
735 data will be written to it.
739 If the C<$output> parameter is a filehandle, the uncompressed data
740 will be written to it.
741 The string '-' can be used as an alias for standard output.
744 =item A scalar reference
746 If C<$output> is a scalar reference, the uncompressed data will be
747 stored in C<$$output>.
751 =item An Array Reference
753 If C<$output> is an array reference, the uncompressed data will be
754 pushed onto the array.
756 =item An Output FileGlob
758 If C<$output> is a string that is delimited by the characters "<" and ">"
759 C<unzip> will assume that it is an I<output fileglob string>. The
760 output is the list of files that match the fileglob.
762 When C<$output> is an fileglob string, C<$input> must also be a fileglob
763 string. Anything else is an error.
767 If the C<$output> parameter is any other type, C<undef> will be returned.
773 When C<$input> maps to multiple files/buffers and C<$output> is a single
774 file/buffer the uncompressed input files/buffers will all be stored
775 in C<$output> as a single uncompressed stream.
779 =head2 Optional Parameters
781 Unless specified below, the optional parameters for C<unzip>,
782 C<OPTS>, are the same as those used with the OO interface defined in the
783 L</"Constructor Options"> section below.
787 =item AutoClose =E<gt> 0|1
789 This option applies to any input or output data streams to
790 C<unzip> that are filehandles.
792 If C<AutoClose> is specified, and the value is true, it will result in all
793 input and/or output filehandles being closed once C<unzip> has
796 This parameter defaults to 0.
800 =item BinModeOut =E<gt> 0|1
802 When writing to a file or filehandle, set C<binmode> before writing to the
811 =item -Append =E<gt> 0|1
815 =item -MultiStream =E<gt> 0|1
817 Creates a new stream after each file.
830 To read the contents of the file C<file1.txt.zip> and write the
831 compressed data to the file C<file1.txt>.
835 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
837 my $input = "file1.txt.zip";
838 my $output = "file1.txt";
839 unzip $input => $output
840 or die "unzip failed: $UnzipError\n";
843 To read from an existing Perl filehandle, C<$input>, and write the
844 uncompressed data to a buffer, C<$buffer>.
848 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
851 my $input = new IO::File "<file1.txt.zip"
852 or die "Cannot open 'file1.txt.zip': $!\n" ;
854 unzip $input => \$buffer
855 or die "unzip failed: $UnzipError\n";
857 To uncompress all files in the directory "/my/home" that match "*.txt.zip" and store the compressed data in the same directory
861 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
863 unzip '</my/home/*.txt.zip>' => '</my/home/#1.txt>'
864 or die "unzip failed: $UnzipError\n";
866 and if you want to compress each file one at a time, this will do the trick
870 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
872 for my $input ( glob "/my/home/*.txt.zip" )
875 $output =~ s/.zip// ;
876 unzip $input => $output
877 or die "Error compressing '$input': $UnzipError\n";
884 The format of the constructor for IO::Uncompress::Unzip is shown below
887 my $z = new IO::Uncompress::Unzip $input [OPTS]
888 or die "IO::Uncompress::Unzip failed: $UnzipError\n";
890 Returns an C<IO::Uncompress::Unzip> object on success and undef on failure.
891 The variable C<$UnzipError> will contain an error message on failure.
893 If you are running Perl 5.005 or better the object, C<$z>, returned from
894 IO::Uncompress::Unzip can be used exactly like an L<IO::File|IO::File> filehandle.
895 This means that all normal input file operations can be carried out with
896 C<$z>. For example, to read a line from a compressed file/buffer you can
897 use either of these forms
899 $line = $z->getline();
902 The mandatory parameter C<$input> is used to determine the source of the
903 compressed data. This parameter can take one of three forms.
909 If the C<$input> parameter is a scalar, it is assumed to be a filename. This
910 file will be opened for reading and the compressed data will be read from it.
914 If the C<$input> parameter is a filehandle, the compressed data will be
916 The string '-' can be used as an alias for standard input.
919 =item A scalar reference
921 If C<$input> is a scalar reference, the compressed data will be read from
926 =head2 Constructor Options
929 The option names defined below are case insensitive and can be optionally
930 prefixed by a '-'. So all of the following are valid
937 OPTS is a combination of the following options:
941 =item -AutoClose =E<gt> 0|1
943 This option is only valid when the C<$input> parameter is a filehandle. If
944 specified, and the value is true, it will result in the file being closed once
945 either the C<close> method is called or the IO::Uncompress::Unzip object is
948 This parameter defaults to 0.
950 =item -MultiStream =E<gt> 0|1
954 Allows multiple concatenated compressed streams to be treated as a single
955 compressed stream. Decompression will stop once either the end of the
956 file/buffer is reached, an error is encountered (premature eof, corrupt
957 compressed data) or the end of a stream is not immediately followed by the
958 start of another stream.
960 This parameter defaults to 0.
964 =item -Prime =E<gt> $string
966 This option will uncompress the contents of C<$string> before processing the
969 This option can be useful when the compressed data is embedded in another
970 file/data structure and it is not possible to work out where the compressed
971 data begins without having to read the first few bytes. If this is the
972 case, the uncompression can be I<primed> with these bytes using this
975 =item -Transparent =E<gt> 0|1
977 If this option is set and the input file or buffer is not compressed data,
978 the module will allow reading of it anyway.
980 This option defaults to 1.
982 =item -BlockSize =E<gt> $num
984 When reading the compressed input data, IO::Uncompress::Unzip will read it in
985 blocks of C<$num> bytes.
987 This option defaults to 4096.
989 =item -InputLength =E<gt> $size
991 When present this option will limit the number of compressed bytes read
992 from the input file/buffer to C<$size>. This option can be used in the
993 situation where there is useful data directly after the compressed data
994 stream and you know beforehand the exact length of the compressed data
997 This option is mostly used when reading from a filehandle, in which case
998 the file pointer will be left pointing to the first byte directly after the
999 compressed data stream.
1003 This option defaults to off.
1005 =item -Append =E<gt> 0|1
1007 This option controls what the C<read> method does with uncompressed data.
1009 If set to 1, all uncompressed data will be appended to the output parameter
1010 of the C<read> method.
1012 If set to 0, the contents of the output parameter of the C<read> method
1013 will be overwritten by the uncompressed data.
1017 =item -Strict =E<gt> 0|1
1021 This option controls whether the extra checks defined below are used when
1022 carrying out the decompression. When Strict is on, the extra tests are
1023 carried out, when Strict is off they are not.
1025 The default for this option is off.
1052 $status = $z->read($buffer)
1054 Reads a block of compressed data (the size the the compressed block is
1055 determined by the C<Buffer> option in the constructor), uncompresses it and
1056 writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
1057 set in the constructor, the uncompressed data will be appended to the
1058 C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
1060 Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
1061 or a negative number on error.
1067 $status = $z->read($buffer, $length)
1068 $status = $z->read($buffer, $length, $offset)
1070 $status = read($z, $buffer, $length)
1071 $status = read($z, $buffer, $length, $offset)
1073 Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
1075 The main difference between this form of the C<read> method and the
1076 previous one, is that this one will attempt to return I<exactly> C<$length>
1077 bytes. The only circumstances that this function will not is if end-of-file
1078 or an IO error is encountered.
1080 Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
1081 or a negative number on error.
1088 $line = $z->getline()
1091 Reads a single line.
1093 This method fully supports the use of of the variable C<$/>
1094 (or C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
1095 determine what constitutes an end of line. Both paragraph mode and file
1096 slurp mode are supported.
1105 Read a single character.
1111 $char = $z->ungetc($string)
1119 $status = $z->inflateSync()
1124 =head2 getHeaderInfo
1128 $hdr = $z->getHeaderInfo();
1129 @hdrs = $z->getHeaderInfo();
1131 This method returns either a hash reference (in scalar context) or a list
1132 or hash references (in array context) that contains information about each
1133 of the header fields in the compressed data stream(s).
1145 Returns the uncompressed file offset.
1156 Returns true if the end of the compressed input stream has been reached.
1162 $z->seek($position, $whence);
1163 seek($z, $position, $whence);
1168 Provides a sub-set of the C<seek> functionality, with the restriction
1169 that it is only legal to seek forward in the input file/buffer.
1170 It is a fatal error to attempt to seek backward.
1174 The C<$whence> parameter takes one the usual values, namely SEEK_SET,
1175 SEEK_CUR or SEEK_END.
1177 Returns 1 on success, 0 on failure.
1186 This is a noop provided for completeness.
1192 Returns true if the object currently refers to a opened file/buffer.
1196 my $prev = $z->autoflush()
1197 my $prev = $z->autoflush(EXPR)
1199 If the C<$z> object is associated with a file or a filehandle, this method
1200 returns the current autoflush setting for the underlying filehandle. If
1201 C<EXPR> is present, and is non-zero, it will enable flushing after every
1202 write/print operation.
1204 If C<$z> is associated with a buffer, this method has no effect and always
1207 B<Note> that the special variable C<$|> B<cannot> be used to set or
1208 retrieve the autoflush setting.
1210 =head2 input_line_number
1212 $z->input_line_number()
1213 $z->input_line_number(EXPR)
1217 Returns the current uncompressed line number. If C<EXPR> is present it has
1218 the effect of setting the line number. Note that setting the line number
1219 does not change the current position within the file/buffer being read.
1221 The contents of C<$/> are used to to determine what constitutes a line
1231 If the C<$z> object is associated with a file or a filehandle, this method
1232 will return the underlying file descriptor.
1234 If the C<$z> object is is associated with a buffer, this method will
1244 Closes the output file/buffer.
1248 For most versions of Perl this method will be automatically invoked if
1249 the IO::Uncompress::Unzip object is destroyed (either explicitly or by the
1250 variable with the reference to the object going out of scope). The
1251 exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1252 these cases, the C<close> method will be called automatically, but
1253 not until global destruction of all live objects when the program is
1256 Therefore, if you want your scripts to be able to run on all versions
1257 of Perl, you should call C<close> explicitly and not rely on automatic
1260 Returns true on success, otherwise 0.
1262 If the C<AutoClose> option has been enabled when the IO::Uncompress::Unzip
1263 object was created, and the object is associated with a file, the
1264 underlying file will also be closed.
1271 No symbolic constants are required by this IO::Uncompress::Unzip at present.
1277 Imports C<unzip> and C<$UnzipError>.
1280 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1291 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::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1293 L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1295 L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1296 L<Archive::Tar|Archive::Tar>,
1297 L<IO::Zlib|IO::Zlib>
1300 For RFC 1950, 1951 and 1952 see
1301 F<http://www.faqs.org/rfcs/rfc1950.html>,
1302 F<http://www.faqs.org/rfcs/rfc1951.html> and
1303 F<http://www.faqs.org/rfcs/rfc1952.html>
1305 The I<zlib> compression library was written by Jean-loup Gailly
1306 F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>.
1308 The primary site for the I<zlib> compression library is
1309 F<http://www.zlib.org>.
1311 The primary site for gzip is F<http://www.gzip.org>.
1318 This module was written by Paul Marquess, F<pmqs@cpan.org>.
1322 =head1 MODIFICATION HISTORY
1324 See the Changes file.
1326 =head1 COPYRIGHT AND LICENSE
1328 Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
1330 This program is free software; you can redistribute it and/or
1331 modify it under the same terms as Perl itself.