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;
14 use IO::Compress::Zlib::Extra;
15 use IO::Compress::Zip::Constants;
17 use Compress::Raw::Zlib qw(crc32) ;
21 eval { require IO::Uncompress::Adapter::Bunzip2 ;
22 import IO::Uncompress::Adapter::Bunzip2 } ;
28 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $UnzipError);
30 $VERSION = '2.000_12';
33 @ISA = qw(Exporter IO::Uncompress::RawInflate);
34 @EXPORT_OK = qw( $UnzipError unzip );
35 %EXPORT_TAGS = %IO::Uncompress::RawInflate::EXPORT_TAGS ;
36 push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
37 Exporter::export_ok_tags('all');
42 my $obj = createSelfTiedObject($class, \$UnzipError);
43 $obj->_create(undef, 0, @_);
48 my $obj = createSelfTiedObject(undef, \$UnzipError);
49 return $obj->_inf(@_) ;
54 use IO::Compress::Base::Common qw(:Parse);
59 'Name' => [1, 1, Parse_any, undef],
61 # 'Streaming' => [1, 1, Parse_boolean, 1],
70 # unzip always needs crc32
71 $got->value('CRC32' => 1);
73 *$self->{UnzipData}{Name} = $got->value('Name');
84 $self->smartReadExact(\$magic, 4);
86 *$self->{HeaderPending} = $magic ;
88 return $self->HeaderError("Minimum header size is " .
90 if length $magic != 4 ;
92 return $self->HeaderError("Bad Magic")
93 if ! _isZipMagic($magic) ;
95 *$self->{Type} = 'zip';
107 my $name = *$self->{UnzipData}{Name} ;
108 my $hdr = $self->_readZipHeader($magic) ;
112 if (! defined $name || $hdr->{Name} eq $name)
119 if (*$self->{ZipData}{Streaming}) {
124 my $status = $self->smartRead(\$b, 1024 * 16);
130 $status = *$self->{Uncomp}->uncompr(\$b, \$temp_buf, 0, $out);
132 return $self->saveErrorString(undef, *$self->{Uncomp}{Error},
133 *$self->{Uncomp}{ErrorNo})
134 if $self->saveStatus($status) == STATUS_ERROR;
136 if ($status == STATUS_ENDSTREAM) {
137 *$self->{Uncomp}->reset();
138 $self->pushBack($b) ;
144 $self->smartReadExact(\$buffer, $hdr->{TrailerLength})
145 or return $self->saveErrorString(undef, "Truncated file");
148 my $c = $hdr->{CompressedLength};
149 $self->smartReadExact(\$buffer, $c)
150 or return $self->saveErrorString(undef, "Truncated file");
154 $self->chkTrailer($buffer) == STATUS_OK
155 or return $self->saveErrorString(undef, "Truncated file");
157 $hdr = $self->_readFullZipHeader();
159 return $self->saveErrorString(undef, "Cannot find '$name'")
160 if $self->smartEof();
171 my ($sig, $CRC32, $cSize, $uSize) ;
172 if (*$self->{ZipData}{Streaming}) {
173 ($sig, $CRC32, $cSize, $uSize) = unpack("V V V V", $trailer) ;
174 return $self->TrailerError("Data Descriptor signature, got $sig")
175 if $sig != ZIP_DATA_HDR_SIG;
178 ($CRC32, $cSize, $uSize) =
179 (*$self->{ZipData}{Crc32},
180 *$self->{ZipData}{CompressedLen},
181 *$self->{ZipData}{UnCompressedLen});
184 if (*$self->{Strict}) {
185 return $self->TrailerError("CRC mismatch")
186 if $CRC32 != *$self->{ZipData}{CRC32} ;
188 my $exp_isize = *$self->{Uncomp}->compressedBytes();
189 return $self->TrailerError("CSIZE mismatch. Got $cSize"
190 . ", expected $exp_isize")
191 if $cSize != $exp_isize ;
193 $exp_isize = *$self->{Uncomp}->uncompressedBytes();
194 return $self->TrailerError("USIZE mismatch. Got $uSize"
195 . ", expected $exp_isize")
196 if $uSize != $exp_isize ;
199 my $reachedEnd = STATUS_ERROR ;
200 # check for central directory or end of central directory
204 my $got = $self->smartRead(\$magic, 4);
206 return $self->saveErrorString(STATUS_ERROR, "Truncated file")
207 if $got != 4 && *$self->{Strict};
213 return STATUS_ERROR ;
216 $self->pushBack($magic) ;
220 my $sig = unpack("V", $magic) ;
222 if ($sig == ZIP_CENTRAL_HDR_SIG)
224 if ($self->skipCentralDirectory($magic) != STATUS_OK ) {
225 if (*$self->{Strict}) {
226 return STATUS_ERROR ;
234 elsif ($sig == ZIP_END_CENTRAL_HDR_SIG)
236 if ($self->skipEndCentralDirectory($magic) != STATUS_OK) {
237 if (*$self->{Strict}) {
238 return STATUS_ERROR ;
245 # $reachedEnd = STATUS_OK ;
249 elsif ($sig == ZIP_LOCAL_HDR_SIG)
251 $self->pushBack($magic) ;
257 $self->pushBack($magic) ;
265 sub skipCentralDirectory
271 $self->smartReadExact(\$buffer, 46 - 4)
272 or return $self->TrailerError("Minimum header size is " .
275 my $keep = $magic . $buffer ;
276 *$self->{HeaderPending} = $keep ;
278 #my $versionMadeBy = unpack ("v", substr($buffer, 4-4, 2));
279 #my $extractVersion = unpack ("v", substr($buffer, 6-4, 2));
280 #my $gpFlag = unpack ("v", substr($buffer, 8-4, 2));
281 #my $compressedMethod = unpack ("v", substr($buffer, 10-4, 2));
282 #my $lastModTime = unpack ("V", substr($buffer, 12-4, 4));
283 #my $crc32 = unpack ("V", substr($buffer, 16-4, 4));
284 #my $compressedLength = unpack ("V", substr($buffer, 20-4, 4));
285 #my $uncompressedLength = unpack ("V", substr($buffer, 24-4, 4));
286 my $filename_length = unpack ("v", substr($buffer, 28-4, 2));
287 my $extra_length = unpack ("v", substr($buffer, 30-4, 2));
288 my $comment_length = unpack ("v", substr($buffer, 32-4, 2));
289 #my $disk_start = unpack ("v", substr($buffer, 34-4, 2));
290 #my $int_file_attrib = unpack ("v", substr($buffer, 36-4, 2));
291 #my $ext_file_attrib = unpack ("V", substr($buffer, 38-4, 2));
292 #my $lcl_hdr_offset = unpack ("V", substr($buffer, 42-4, 2));
298 if ($filename_length)
300 $self->smartReadExact(\$filename, $filename_length)
301 or return $self->TruncatedTrailer("filename");
307 $self->smartReadExact(\$extraField, $extra_length)
308 or return $self->TruncatedTrailer("extra");
309 $keep .= $extraField ;
314 $self->smartReadExact(\$comment, $comment_length)
315 or return $self->TruncatedTrailer("comment");
322 sub skipEndCentralDirectory
328 $self->smartReadExact(\$buffer, 22 - 4)
329 or return $self->TrailerError("Minimum header size is " .
332 my $keep = $magic . $buffer ;
333 *$self->{HeaderPending} = $keep ;
335 #my $diskNumber = unpack ("v", substr($buffer, 4-4, 2));
336 #my $cntrlDirDiskNo = unpack ("v", substr($buffer, 6-4, 2));
337 #my $entriesInThisCD = unpack ("v", substr($buffer, 8-4, 2));
338 #my $entriesInCD = unpack ("v", substr($buffer, 10-4, 2));
339 #my $sizeOfCD = unpack ("V", substr($buffer, 12-4, 2));
340 #my $offsetToCD = unpack ("V", substr($buffer, 16-4, 2));
341 my $comment_length = unpack ("v", substr($buffer, 20-4, 2));
347 $self->smartReadExact(\$comment, $comment_length)
348 or return $self->TruncatedTrailer("comment");
361 return 0 if length $buffer < 4 ;
362 my $sig = unpack("V", $buffer) ;
363 return $sig == ZIP_LOCAL_HDR_SIG ;
367 sub _readFullZipHeader($)
372 $self->smartReadExact(\$magic, 4);
374 *$self->{HeaderPending} = $magic ;
376 return $self->HeaderError("Minimum header size is " .
378 if length $magic != 4 ;
381 return $self->HeaderError("Bad Magic")
382 if ! _isZipMagic($magic) ;
384 my $status = $self->_readZipHeader($magic);
385 delete *$self->{Transparent} if ! defined $status ;
389 sub _readZipHeader($)
391 my ($self, $magic) = @_ ;
395 $self->smartReadExact(\$buffer, 30 - 4)
396 or return $self->HeaderError("Minimum header size is " .
399 my $keep = $magic . $buffer ;
400 *$self->{HeaderPending} = $keep ;
402 my $extractVersion = unpack ("v", substr($buffer, 4-4, 2));
403 my $gpFlag = unpack ("v", substr($buffer, 6-4, 2));
404 my $compressedMethod = unpack ("v", substr($buffer, 8-4, 2));
405 my $lastModTime = unpack ("V", substr($buffer, 10-4, 4));
406 my $crc32 = unpack ("V", substr($buffer, 14-4, 4));
407 my $compressedLength = unpack ("V", substr($buffer, 18-4, 4));
408 my $uncompressedLength = unpack ("V", substr($buffer, 22-4, 4));
409 my $filename_length = unpack ("v", substr($buffer, 26-4, 2));
410 my $extra_length = unpack ("v", substr($buffer, 28-4, 2));
415 my $streamingMode = ($gpFlag & ZIP_GP_FLAG_STREAMING_MASK) ? 1 : 0 ;
417 return $self->HeaderError("Streamed Stored content not supported")
418 if $streamingMode && $compressedMethod == 0 ;
420 *$self->{ZipData}{Streaming} = $streamingMode;
422 if (! $streamingMode) {
423 *$self->{ZipData}{Streaming} = 0;
424 *$self->{ZipData}{Crc32} = $crc32;
425 *$self->{ZipData}{CompressedLen} = $compressedLength;
426 *$self->{ZipData}{UnCompressedLen} = $uncompressedLength;
427 *$self->{CompressedInputLengthRemaining} =
428 *$self->{CompressedInputLength} = $compressedLength;
432 if ($filename_length)
434 $self->smartReadExact(\$filename, $filename_length)
435 or return $self->TruncatedHeader("Filename");
441 $self->smartReadExact(\$extraField, $extra_length)
442 or return $self->TruncatedHeader("Extra Field");
444 my $bad = IO::Compress::Zlib::Extra::parseRawExtra($extraField,
446 return $self->HeaderError($bad)
449 $keep .= $extraField ;
452 *$self->{ZipData}{Method} = $compressedMethod;
453 if ($compressedMethod == ZIP_CM_DEFLATE)
455 *$self->{Type} = 'zip-deflate';
457 elsif ($compressedMethod == ZIP_CM_BZIP2)
459 #if (! defined $IO::Uncompress::Adapter::Bunzip2::VERSION)
461 *$self->{Type} = 'zip-bzip2';
463 my $obj = IO::Uncompress::Adapter::Bunzip2::mkUncompObject(
466 *$self->{Uncomp} = $obj;
467 *$self->{ZipData}{CRC32} = crc32(undef);
470 elsif ($compressedMethod == ZIP_CM_STORE)
472 # TODO -- add support for reading uncompressed
474 *$self->{Type} = 'zip-stored';
476 my $obj = IO::Uncompress::Adapter::Identity::mkUncompObject(# $got->value('CRC32'),
477 # $got->value('ADLER32'),
480 *$self->{Uncomp} = $obj;
485 return $self->HeaderError("Unsupported Compression format $compressedMethod");
490 'FingerprintLength' => 4,
491 #'HeaderLength' => $compressedMethod == 8 ? length $keep : 0,
492 'HeaderLength' => length $keep,
493 'TrailerLength' => $streamingMode ? 16 : 0,
495 'CompressedLength' => $compressedLength ,
496 'UncompressedLength' => $uncompressedLength ,
499 'Time' => _dosToUnixTime($lastModTime),
500 'Stream' => $streamingMode,
502 'MethodID' => $compressedMethod,
503 'MethodName' => $compressedMethod == ZIP_CM_DEFLATE
505 : $compressedMethod == ZIP_CM_BZIP2
507 : $compressedMethod == ZIP_CM_STORE
511 # 'TextFlag' => $flag & GZIP_FLG_FTEXT ? 1 : 0,
512 # 'HeaderCRCFlag' => $flag & GZIP_FLG_FHCRC ? 1 : 0,
513 # 'NameFlag' => $flag & GZIP_FLG_FNAME ? 1 : 0,
514 # 'CommentFlag' => $flag & GZIP_FLG_FCOMMENT ? 1 : 0,
515 # 'ExtraFlag' => $flag & GZIP_FLG_FEXTRA ? 1 : 0,
516 # 'Comment' => $comment,
518 # 'OsName' => defined $GZIP_OS_Names{$os}
519 # ? $GZIP_OS_Names{$os} : "Unknown",
520 # 'HeaderCRC' => $HeaderCRC,
522 # 'ExtraFlags' => $xfl,
523 'ExtraFieldRaw' => $extraField,
524 'ExtraField' => [ @EXTRA ],
530 sub filterUncompressed
534 if (*$self->{ZipData}{Method} == 12) {
535 *$self->{ZipData}{CRC32} = crc32(${$_[0]}, *$self->{ZipData}{CRC32});
538 *$self->{ZipData}{CRC32} = *$self->{Uncomp}->crc32() ;
546 #use Time::Local 'timelocal_nocheck';
547 use Time::Local 'timelocal';
551 my $year = ( ( $dt >> 25 ) & 0x7f ) + 80;
552 my $mon = ( ( $dt >> 21 ) & 0x0f ) - 1;
553 my $mday = ( ( $dt >> 16 ) & 0x1f );
555 my $hour = ( ( $dt >> 11 ) & 0x1f );
556 my $min = ( ( $dt >> 5 ) & 0x3f );
557 my $sec = ( ( $dt << 1 ) & 0x3e );
561 eval { timelocal( $sec, $min, $hour, $mday, $mon, $year ); };
577 IO::Uncompress::Unzip - Read zip files/buffers
583 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
585 my $status = unzip $input => $output [,OPTS]
586 or die "unzip failed: $UnzipError\n";
588 my $z = new IO::Uncompress::Unzip $input [OPTS]
589 or die "unzip failed: $UnzipError\n";
591 $status = $z->read($buffer)
592 $status = $z->read($buffer, $length)
593 $status = $z->read($buffer, $length, $offset)
594 $line = $z->getline()
599 $status = $z->inflateSync()
602 $data = $z->getHeaderInfo()
604 $z->seek($position, $whence)
616 read($z, $buffer, $length);
617 read($z, $buffer, $length, $offset);
619 seek($z, $position, $whence)
630 B<WARNING -- This is a Beta release>.
634 =item * DO NOT use in production code.
636 =item * The documentation is incomplete in places.
638 =item * Parts of the interface defined here are tentative.
640 =item * Please report any problems you find.
648 This module provides a Perl interface that allows the reading of
651 For writing zip files/buffers, see the companion module IO::Compress::Zip.
658 =head1 Functional Interface
660 A top-level function, C<unzip>, is provided to carry out
661 "one-shot" uncompression between buffers and/or files. For finer
662 control over the uncompression process, see the L</"OO Interface">
665 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
667 unzip $input => $output [,OPTS]
668 or die "unzip failed: $UnzipError\n";
672 The functional interface needs Perl5.005 or better.
675 =head2 unzip $input => $output [, OPTS]
678 C<unzip> expects at least two parameters, C<$input> and C<$output>.
680 =head3 The C<$input> parameter
682 The parameter, C<$input>, is used to define the source of
685 It can take one of the following forms:
691 If the C<$input> parameter is a simple scalar, it is assumed to be a
692 filename. This file will be opened for reading and the input data
693 will be read from it.
697 If the C<$input> parameter is a filehandle, the input data will be
699 The string '-' can be used as an alias for standard input.
701 =item A scalar reference
703 If C<$input> is a scalar reference, the input data will be read
706 =item An array reference
708 If C<$input> is an array reference, each element in the array must be a
711 The input data will be read from each file in turn.
713 The complete array will be walked to ensure that it only
714 contains valid filenames before any data is uncompressed.
718 =item An Input FileGlob string
720 If C<$input> is a string that is delimited by the characters "<" and ">"
721 C<unzip> will assume that it is an I<input fileglob string>. The
722 input is the list of files that match the fileglob.
724 If the fileglob does not match any files ...
726 See L<File::GlobMapper|File::GlobMapper> for more details.
731 If the C<$input> parameter is any other type, C<undef> will be returned.
735 =head3 The C<$output> parameter
737 The parameter C<$output> is used to control the destination of the
738 uncompressed data. This parameter can take one of these forms.
744 If the C<$output> parameter is a simple scalar, it is assumed to be a
745 filename. This file will be opened for writing and the uncompressed
746 data will be written to it.
750 If the C<$output> parameter is a filehandle, the uncompressed data
751 will be written to it.
752 The string '-' can be used as an alias for standard output.
755 =item A scalar reference
757 If C<$output> is a scalar reference, the uncompressed data will be
758 stored in C<$$output>.
762 =item An Array Reference
764 If C<$output> is an array reference, the uncompressed data will be
765 pushed onto the array.
767 =item An Output FileGlob
769 If C<$output> is a string that is delimited by the characters "<" and ">"
770 C<unzip> will assume that it is an I<output fileglob string>. The
771 output is the list of files that match the fileglob.
773 When C<$output> is an fileglob string, C<$input> must also be a fileglob
774 string. Anything else is an error.
778 If the C<$output> parameter is any other type, C<undef> will be returned.
785 When C<$input> maps to multiple compressed files/buffers and C<$output> is
786 a single file/buffer, after uncompression C<$output> will contain a
787 concatenation of all the uncompressed data from each of the input
794 =head2 Optional Parameters
796 Unless specified below, the optional parameters for C<unzip>,
797 C<OPTS>, are the same as those used with the OO interface defined in the
798 L</"Constructor Options"> section below.
802 =item AutoClose =E<gt> 0|1
804 This option applies to any input or output data streams to
805 C<unzip> that are filehandles.
807 If C<AutoClose> is specified, and the value is true, it will result in all
808 input and/or output filehandles being closed once C<unzip> has
811 This parameter defaults to 0.
815 =item BinModeOut =E<gt> 0|1
817 When writing to a file or filehandle, set C<binmode> before writing to the
826 =item -Append =E<gt> 0|1
830 =item -MultiStream =E<gt> 0|1
832 Creates a new stream after each file.
845 To read the contents of the file C<file1.txt.zip> and write the
846 compressed data to the file C<file1.txt>.
850 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
852 my $input = "file1.txt.zip";
853 my $output = "file1.txt";
854 unzip $input => $output
855 or die "unzip failed: $UnzipError\n";
858 To read from an existing Perl filehandle, C<$input>, and write the
859 uncompressed data to a buffer, C<$buffer>.
863 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
866 my $input = new IO::File "<file1.txt.zip"
867 or die "Cannot open 'file1.txt.zip': $!\n" ;
869 unzip $input => \$buffer
870 or die "unzip failed: $UnzipError\n";
872 To uncompress all files in the directory "/my/home" that match "*.txt.zip" and store the compressed data in the same directory
876 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
878 unzip '</my/home/*.txt.zip>' => '</my/home/#1.txt>'
879 or die "unzip failed: $UnzipError\n";
881 and if you want to compress each file one at a time, this will do the trick
885 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
887 for my $input ( glob "/my/home/*.txt.zip" )
890 $output =~ s/.zip// ;
891 unzip $input => $output
892 or die "Error compressing '$input': $UnzipError\n";
899 The format of the constructor for IO::Uncompress::Unzip is shown below
902 my $z = new IO::Uncompress::Unzip $input [OPTS]
903 or die "IO::Uncompress::Unzip failed: $UnzipError\n";
905 Returns an C<IO::Uncompress::Unzip> object on success and undef on failure.
906 The variable C<$UnzipError> will contain an error message on failure.
908 If you are running Perl 5.005 or better the object, C<$z>, returned from
909 IO::Uncompress::Unzip can be used exactly like an L<IO::File|IO::File> filehandle.
910 This means that all normal input file operations can be carried out with
911 C<$z>. For example, to read a line from a compressed file/buffer you can
912 use either of these forms
914 $line = $z->getline();
917 The mandatory parameter C<$input> is used to determine the source of the
918 compressed data. This parameter can take one of three forms.
924 If the C<$input> parameter is a scalar, it is assumed to be a filename. This
925 file will be opened for reading and the compressed data will be read from it.
929 If the C<$input> parameter is a filehandle, the compressed data will be
931 The string '-' can be used as an alias for standard input.
934 =item A scalar reference
936 If C<$input> is a scalar reference, the compressed data will be read from
941 =head2 Constructor Options
944 The option names defined below are case insensitive and can be optionally
945 prefixed by a '-'. So all of the following are valid
952 OPTS is a combination of the following options:
956 =item -AutoClose =E<gt> 0|1
958 This option is only valid when the C<$input> parameter is a filehandle. If
959 specified, and the value is true, it will result in the file being closed once
960 either the C<close> method is called or the IO::Uncompress::Unzip object is
963 This parameter defaults to 0.
965 =item -MultiStream =E<gt> 0|1
969 Allows multiple concatenated compressed streams to be treated as a single
970 compressed stream. Decompression will stop once either the end of the
971 file/buffer is reached, an error is encountered (premature eof, corrupt
972 compressed data) or the end of a stream is not immediately followed by the
973 start of another stream.
975 This parameter defaults to 0.
979 =item -Prime =E<gt> $string
981 This option will uncompress the contents of C<$string> before processing the
984 This option can be useful when the compressed data is embedded in another
985 file/data structure and it is not possible to work out where the compressed
986 data begins without having to read the first few bytes. If this is the
987 case, the uncompression can be I<primed> with these bytes using this
990 =item -Transparent =E<gt> 0|1
992 If this option is set and the input file or buffer is not compressed data,
993 the module will allow reading of it anyway.
995 This option defaults to 1.
997 =item -BlockSize =E<gt> $num
999 When reading the compressed input data, IO::Uncompress::Unzip will read it in
1000 blocks of C<$num> bytes.
1002 This option defaults to 4096.
1004 =item -InputLength =E<gt> $size
1006 When present this option will limit the number of compressed bytes read
1007 from the input file/buffer to C<$size>. This option can be used in the
1008 situation where there is useful data directly after the compressed data
1009 stream and you know beforehand the exact length of the compressed data
1012 This option is mostly used when reading from a filehandle, in which case
1013 the file pointer will be left pointing to the first byte directly after the
1014 compressed data stream.
1018 This option defaults to off.
1020 =item -Append =E<gt> 0|1
1022 This option controls what the C<read> method does with uncompressed data.
1024 If set to 1, all uncompressed data will be appended to the output parameter
1025 of the C<read> method.
1027 If set to 0, the contents of the output parameter of the C<read> method
1028 will be overwritten by the uncompressed data.
1032 =item -Strict =E<gt> 0|1
1036 This option controls whether the extra checks defined below are used when
1037 carrying out the decompression. When Strict is on, the extra tests are
1038 carried out, when Strict is off they are not.
1040 The default for this option is off.
1067 $status = $z->read($buffer)
1069 Reads a block of compressed data (the size the the compressed block is
1070 determined by the C<Buffer> option in the constructor), uncompresses it and
1071 writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
1072 set in the constructor, the uncompressed data will be appended to the
1073 C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
1075 Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
1076 or a negative number on error.
1082 $status = $z->read($buffer, $length)
1083 $status = $z->read($buffer, $length, $offset)
1085 $status = read($z, $buffer, $length)
1086 $status = read($z, $buffer, $length, $offset)
1088 Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
1090 The main difference between this form of the C<read> method and the
1091 previous one, is that this one will attempt to return I<exactly> C<$length>
1092 bytes. The only circumstances that this function will not is if end-of-file
1093 or an IO error is encountered.
1095 Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
1096 or a negative number on error.
1103 $line = $z->getline()
1106 Reads a single line.
1108 This method fully supports the use of of the variable C<$/>
1109 (or C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
1110 determine what constitutes an end of line. Both paragraph mode and file
1111 slurp mode are supported.
1120 Read a single character.
1126 $char = $z->ungetc($string)
1134 $status = $z->inflateSync()
1139 =head2 getHeaderInfo
1143 $hdr = $z->getHeaderInfo();
1144 @hdrs = $z->getHeaderInfo();
1146 This method returns either a hash reference (in scalar context) or a list
1147 or hash references (in array context) that contains information about each
1148 of the header fields in the compressed data stream(s).
1160 Returns the uncompressed file offset.
1171 Returns true if the end of the compressed input stream has been reached.
1177 $z->seek($position, $whence);
1178 seek($z, $position, $whence);
1183 Provides a sub-set of the C<seek> functionality, with the restriction
1184 that it is only legal to seek forward in the input file/buffer.
1185 It is a fatal error to attempt to seek backward.
1189 The C<$whence> parameter takes one the usual values, namely SEEK_SET,
1190 SEEK_CUR or SEEK_END.
1192 Returns 1 on success, 0 on failure.
1201 This is a noop provided for completeness.
1207 Returns true if the object currently refers to a opened file/buffer.
1211 my $prev = $z->autoflush()
1212 my $prev = $z->autoflush(EXPR)
1214 If the C<$z> object is associated with a file or a filehandle, this method
1215 returns the current autoflush setting for the underlying filehandle. If
1216 C<EXPR> is present, and is non-zero, it will enable flushing after every
1217 write/print operation.
1219 If C<$z> is associated with a buffer, this method has no effect and always
1222 B<Note> that the special variable C<$|> B<cannot> be used to set or
1223 retrieve the autoflush setting.
1225 =head2 input_line_number
1227 $z->input_line_number()
1228 $z->input_line_number(EXPR)
1232 Returns the current uncompressed line number. If C<EXPR> is present it has
1233 the effect of setting the line number. Note that setting the line number
1234 does not change the current position within the file/buffer being read.
1236 The contents of C<$/> are used to to determine what constitutes a line
1246 If the C<$z> object is associated with a file or a filehandle, this method
1247 will return the underlying file descriptor.
1249 If the C<$z> object is is associated with a buffer, this method will
1259 Closes the output file/buffer.
1263 For most versions of Perl this method will be automatically invoked if
1264 the IO::Uncompress::Unzip object is destroyed (either explicitly or by the
1265 variable with the reference to the object going out of scope). The
1266 exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1267 these cases, the C<close> method will be called automatically, but
1268 not until global destruction of all live objects when the program is
1271 Therefore, if you want your scripts to be able to run on all versions
1272 of Perl, you should call C<close> explicitly and not rely on automatic
1275 Returns true on success, otherwise 0.
1277 If the C<AutoClose> option has been enabled when the IO::Uncompress::Unzip
1278 object was created, and the object is associated with a file, the
1279 underlying file will also be closed.
1286 No symbolic constants are required by this IO::Uncompress::Unzip at present.
1292 Imports C<unzip> and C<$UnzipError>.
1295 use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
1306 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>
1308 L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1310 L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1311 L<Archive::Tar|Archive::Tar>,
1312 L<IO::Zlib|IO::Zlib>
1315 For RFC 1950, 1951 and 1952 see
1316 F<http://www.faqs.org/rfcs/rfc1950.html>,
1317 F<http://www.faqs.org/rfcs/rfc1951.html> and
1318 F<http://www.faqs.org/rfcs/rfc1952.html>
1320 The I<zlib> compression library was written by Jean-loup Gailly
1321 F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>.
1323 The primary site for the I<zlib> compression library is
1324 F<http://www.zlib.org>.
1326 The primary site for gzip is F<http://www.gzip.org>.
1333 This module was written by Paul Marquess, F<pmqs@cpan.org>.
1337 =head1 MODIFICATION HISTORY
1339 See the Changes file.
1341 =head1 COPYRIGHT AND LICENSE
1343 Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
1345 This program is free software; you can redistribute it and/or
1346 modify it under the same terms as Perl itself.