.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Archive::Zip 3"
.TH Archive::Zip 3 "2021-08-09" "perl v5.32.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Archive::Zip \- Provide an interface to ZIP archive files.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\&   # Create a Zip file
\&   use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
\&   my $zip = Archive::Zip\->new();
\&
\&   # Add a directory
\&   my $dir_member = $zip\->addDirectory( \*(Aqdirname/\*(Aq );
\&
\&   # Add a file from a string with compression
\&   my $string_member = $zip\->addString( \*(AqThis is a test\*(Aq, \*(AqstringMember.txt\*(Aq );
\&   $string_member\->desiredCompressionMethod( COMPRESSION_DEFLATED );
\&
\&   # Add a file from disk
\&   my $file_member = $zip\->addFile( \*(Aqxyz.pl\*(Aq, \*(AqAnotherName.pl\*(Aq );
\&
\&   # Save the Zip file
\&   unless ( $zip\->writeToFileNamed(\*(AqsomeZip.zip\*(Aq) == AZ_OK ) {
\&       die \*(Aqwrite error\*(Aq;
\&   }
\&
\&   # Read a Zip file
\&   my $somezip = Archive::Zip\->new();
\&   unless ( $somezip\->read( \*(AqsomeZip.zip\*(Aq ) == AZ_OK ) {
\&       die \*(Aqread error\*(Aq;
\&   }
\&
\&   # Change the compression type for a file in the Zip
\&   my $member = $somezip\->memberNamed( \*(AqstringMember.txt\*(Aq );
\&   $member\->desiredCompressionMethod( COMPRESSION_STORED );
\&   unless ( $zip\->writeToFileNamed( \*(AqsomeOtherZip.zip\*(Aq ) == AZ_OK ) {
\&       die \*(Aqwrite error\*(Aq;
\&   }
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The Archive::Zip module allows a Perl program to create, manipulate, read,
and write Zip archive files.
.PP
Zip archives can be created, or you can read from existing zip files.
.PP
Once created, they can be written to files, streams, or strings. Members
can be added, removed, extracted, replaced, rearranged, and enumerated.
They can also be renamed or have their dates, comments, or other attributes
queried or modified. Their data can be compressed or uncompressed as needed.
.PP
Members can be created from members in existing Zip files, or from existing
directories, files, or strings.
.PP
This module uses the Compress::Raw::Zlib library to read and write the
compressed streams inside the files.
.PP
One can use Archive::Zip::MemberRead to read the zip file archive members
as if they were files.
.SS "File Naming"
.IX Subsection "File Naming"
Regardless of what your local file system uses for file naming, names in a
Zip file are in Unix format (\fIforward\fR slashes (/) separating directory
names, etc.).
.PP
\&\f(CW\*(C`Archive::Zip\*(C'\fR tries to be consistent with file naming conventions, and will
translate back and forth between native and Zip file names.
.PP
However, it can't guess which format names are in. So two rules control what
kind of file name you must pass various routines:
.IP "Names of files are in local format." 4
.IX Item "Names of files are in local format."
\&\f(CW\*(C`File::Spec\*(C'\fR and \f(CW\*(C`File::Basename\*(C'\fR are used for various file
operations. When you're referring to a file on your system, use its
file naming conventions.
.IP "Names of archive members are in Unix format." 4
.IX Item "Names of archive members are in Unix format."
This applies to every method that refers to an archive member, or
provides a name for new archive members. The \f(CW\*(C`extract()\*(C'\fR methods
that can take one or two names will convert from local to zip names
if you call them with a single name.
.SS "Archive::Zip Object Model"
.IX Subsection "Archive::Zip Object Model"
\fIOverview\fR
.IX Subsection "Overview"
.PP
Archive::Zip::Archive objects are what you ordinarily deal with.
These maintain the structure of a zip file, without necessarily
holding data. When a zip is read from a disk file, the (possibly
compressed) data still lives in the file, not in memory. Archive
members hold information about the individual members, but not
(usually) the actual member data. When the zip is written to a
(different) file, the member data is compressed or copied as needed.
It is possible to make archive members whose data is held in a string
in memory, but this is not done when a zip file is read. Directory
members don't have any data.
.SS "Inheritance"
.IX Subsection "Inheritance"
.Vb 9
\&  Exporter
\&   Archive::Zip                            Common base class, has defs.
\&       Archive::Zip::Archive               A Zip archive.
\&       Archive::Zip::Member                Abstract superclass for all members.
\&           Archive::Zip::StringMember      Member made from a string
\&           Archive::Zip::FileMember        Member made from an external file
\&               Archive::Zip::ZipFileMember Member that lives in a zip file
\&               Archive::Zip::NewFileMember Member whose data is in a file
\&           Archive::Zip::DirectoryMember   Member that is a directory
.Ve
.SH "EXPORTS"
.IX Header "EXPORTS"
.IP ":CONSTANTS" 4
.IX Item ":CONSTANTS"
Exports the following constants:
.Sp
\&\s-1FA_MSDOS FA_UNIX GPBF_ENCRYPTED_MASK
GPBF_DEFLATING_COMPRESSION_MASK GPBF_HAS_DATA_DESCRIPTOR_MASK
COMPRESSION_STORED COMPRESSION_DEFLATED IFA_TEXT_FILE_MASK
IFA_TEXT_FILE IFA_BINARY_FILE COMPRESSION_LEVEL_NONE
COMPRESSION_LEVEL_DEFAULT COMPRESSION_LEVEL_FASTEST
COMPRESSION_LEVEL_BEST_COMPRESSION
ZIP64_SUPPORTED ZIP64_AS_NEEDED ZIP64_EOCD ZIP64_HEADERS\s0
.IP ":MISC_CONSTANTS" 4
.IX Item ":MISC_CONSTANTS"
Exports the following constants (only necessary for extending the
module):
.Sp
\&\s-1FA_AMIGA FA_VAX_VMS FA_VM_CMS FA_ATARI_ST FA_OS2_HPFS
FA_MACINTOSH FA_Z_SYSTEM FA_CPM FA_WINDOWS_NTFS
GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK
GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK
GPBF_IS_COMPRESSED_PATCHED_DATA_MASK COMPRESSION_SHRUNK
DEFLATING_COMPRESSION_NORMAL DEFLATING_COMPRESSION_MAXIMUM
DEFLATING_COMPRESSION_FAST DEFLATING_COMPRESSION_SUPER_FAST
COMPRESSION_REDUCED_1 COMPRESSION_REDUCED_2 COMPRESSION_REDUCED_3
COMPRESSION_REDUCED_4 COMPRESSION_IMPLODED COMPRESSION_TOKENIZED
COMPRESSION_DEFLATED_ENHANCED
COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED\s0
.IP ":ERROR_CODES" 4
.IX Item ":ERROR_CODES"
Explained below. Returned from most methods.
.Sp
\&\s-1AZ_OK AZ_STREAM_END AZ_ERROR AZ_FORMAT_ERROR AZ_IO_ERROR\s0
.SH "ERROR CODES"
.IX Header "ERROR CODES"
Many of the methods in Archive::Zip return error codes. These are implemented
as inline subroutines, using the \f(CW\*(C`use constant\*(C'\fR pragma. They can be imported
into your namespace using the \f(CW\*(C`:ERROR_CODES\*(C'\fR tag:
.PP
.Vb 1
\&  use Archive::Zip qw( :ERROR_CODES );
\&
\&  ...
\&
\&  unless ( $zip\->read( \*(Aqmyfile.zip\*(Aq ) == AZ_OK ) {
\&      die "whoops!";
\&  }
.Ve
.IP "\s-1AZ_OK\s0 (0)" 4
.IX Item "AZ_OK (0)"
Everything is fine.
.IP "\s-1AZ_STREAM_END\s0 (1)" 4
.IX Item "AZ_STREAM_END (1)"
The read stream (or central directory) ended normally.
.IP "\s-1AZ_ERROR\s0 (2)" 4
.IX Item "AZ_ERROR (2)"
There was some generic kind of error.
.IP "\s-1AZ_FORMAT_ERROR\s0 (3)" 4
.IX Item "AZ_FORMAT_ERROR (3)"
There is a format error in a \s-1ZIP\s0 file being read.
.IP "\s-1AZ_IO_ERROR\s0 (4)" 4
.IX Item "AZ_IO_ERROR (4)"
There was an \s-1IO\s0 error.
.SS "Compression"
.IX Subsection "Compression"
Archive::Zip allows each member of a \s-1ZIP\s0 file to be compressed (using the
Deflate algorithm) or uncompressed.
.PP
Other compression algorithms that some versions of \s-1ZIP\s0 have been able to
produce are not supported. Each member has two compression methods: the
one it's stored as (this is always \s-1COMPRESSION_STORED\s0 for string and external
file members), and the one you desire for the member in the zip file.
.PP
These can be different, of course, so you can make a zip member that is not
compressed out of one that is, and vice versa.
.PP
You can inquire about the current compression and set the desired
compression method:
.PP
.Vb 2
\&  my $member = $zip\->memberNamed( \*(Aqxyz.txt\*(Aq );
\&  $member\->compressionMethod();    # return current compression
\&
\&  # set to read uncompressed
\&  $member\->desiredCompressionMethod( COMPRESSION_STORED );
\&
\&  # set to read compressed
\&  $member\->desiredCompressionMethod( COMPRESSION_DEFLATED );
.Ve
.PP
There are two different compression methods:
.IP "\s-1COMPRESSION_STORED\s0" 4
.IX Item "COMPRESSION_STORED"
File is stored (no compression)
.IP "\s-1COMPRESSION_DEFLATED\s0" 4
.IX Item "COMPRESSION_DEFLATED"
File is Deflated
.SS "Compression Levels"
.IX Subsection "Compression Levels"
If a member's desiredCompressionMethod is \s-1COMPRESSION_DEFLATED,\s0 you
can choose different compression levels. This choice may affect the
speed of compression and decompression, as well as the size of the
compressed member data.
.PP
.Vb 1
\&  $member\->desiredCompressionLevel( 9 );
.Ve
.PP
The levels given can be:
.IP "\(bu" 4
0 or \s-1COMPRESSION_LEVEL_NONE\s0
.Sp
This is the same as saying
.Sp
.Vb 1
\&  $member\->desiredCompressionMethod( COMPRESSION_STORED );
.Ve
.IP "\(bu" 4
1 .. 9
.Sp
1 gives the best speed and worst compression, and 9 gives the
best compression and worst speed.
.IP "\(bu" 4
\&\s-1COMPRESSION_LEVEL_FASTEST\s0
.Sp
This is a synonym for level 1.
.IP "\(bu" 4
\&\s-1COMPRESSION_LEVEL_BEST_COMPRESSION\s0
.Sp
This is a synonym for level 9.
.IP "\(bu" 4
\&\s-1COMPRESSION_LEVEL_DEFAULT\s0
.Sp
This gives a good compromise between speed and compression,
and is currently equivalent to 6 (this is in the zlib code).
This is the level that will be used if not specified.
.SH "Archive::Zip Methods"
.IX Header "Archive::Zip Methods"
The Archive::Zip class (and its invisible subclass Archive::Zip::Archive)
implement generic zip file functionality. Creating a new Archive::Zip object
actually makes an Archive::Zip::Archive object, but you don't have to worry
about this unless you're subclassing.
.SS "Constructor"
.IX Subsection "Constructor"
.IP "new( [$fileName] )" 4
.IX Item "new( [$fileName] )"
.PD 0
.ie n .IP "new( { filename => $fileName } )" 4
.el .IP "new( { filename => \f(CW$fileName\fR } )" 4
.IX Item "new( { filename => $fileName } )"
.PD
Make a new, empty zip archive.
.Sp
.Vb 1
\&    my $zip = Archive::Zip\->new();
.Ve
.Sp
If an additional argument is passed, \fBnew()\fR will call \fBread()\fR
to read the contents of an archive:
.Sp
.Vb 1
\&    my $zip = Archive::Zip\->new( \*(Aqxyz.zip\*(Aq );
.Ve
.Sp
If a filename argument is passed and the read fails for any
reason, new will return undef. For this reason, it may be
better to call read separately.
.SS "Zip Archive Utility Methods"
.IX Subsection "Zip Archive Utility Methods"
These Archive::Zip methods may be called as functions or as object
methods. Do not call them as class methods:
.PP
.Vb 4
\&    $zip = Archive::Zip\->new();
\&    $crc = Archive::Zip::computeCRC32( \*(Aqghijkl\*(Aq );    # OK
\&    $crc = $zip\->computeCRC32( \*(Aqghijkl\*(Aq );            # also OK
\&    $crc = Archive::Zip\->computeCRC32( \*(Aqghijkl\*(Aq );    # NOT OK
.Ve
.ie n .IP "Archive::Zip::computeCRC32( $string [, $crc] )" 4
.el .IP "Archive::Zip::computeCRC32( \f(CW$string\fR [, \f(CW$crc\fR] )" 4
.IX Item "Archive::Zip::computeCRC32( $string [, $crc] )"
.PD 0
.ie n .IP "Archive::Zip::computeCRC32( { string => $string [, checksum => $crc ] } )" 4
.el .IP "Archive::Zip::computeCRC32( { string => \f(CW$string\fR [, checksum => \f(CW$crc\fR ] } )" 4
.IX Item "Archive::Zip::computeCRC32( { string => $string [, checksum => $crc ] } )"
.PD
This is a utility function that uses the Compress::Raw::Zlib \s-1CRC\s0
routine to compute a \s-1CRC\-32.\s0 You can get the \s-1CRC\s0 of a string:
.Sp
.Vb 1
\&    $crc = Archive::Zip::computeCRC32( $string );
.Ve
.Sp
Or you can compute the running \s-1CRC:\s0
.Sp
.Vb 3
\&    $crc = 0;
\&    $crc = Archive::Zip::computeCRC32( \*(Aqabcdef\*(Aq, $crc );
\&    $crc = Archive::Zip::computeCRC32( \*(Aqghijkl\*(Aq, $crc );
.Ve
.ie n .IP "Archive::Zip::setChunkSize( $number )" 4
.el .IP "Archive::Zip::setChunkSize( \f(CW$number\fR )" 4
.IX Item "Archive::Zip::setChunkSize( $number )"
.PD 0
.ie n .IP "Archive::Zip::setChunkSize( { chunkSize => $number } )" 4
.el .IP "Archive::Zip::setChunkSize( { chunkSize => \f(CW$number\fR } )" 4
.IX Item "Archive::Zip::setChunkSize( { chunkSize => $number } )"
.PD
Report or change chunk size used for reading and writing.
This can make big differences in dealing with large files.
Currently, this defaults to 32K. This also changes the chunk
size used for Compress::Raw::Zlib. You must call \fBsetChunkSize()\fR
before reading or writing. This is not exportable, so you
must call it like:
.Sp
.Vb 1
\&    Archive::Zip::setChunkSize( 4096 );
.Ve
.Sp
or as a method on a zip (though this is a global setting).
Returns old chunk size.
.IP "\fBArchive::Zip::chunkSize()\fR" 4
.IX Item "Archive::Zip::chunkSize()"
Returns the current chunk size:
.Sp
.Vb 1
\&    my $chunkSize = Archive::Zip::chunkSize();
.Ve
.IP "Archive::Zip::setErrorHandler( \e&subroutine )" 4
.IX Item "Archive::Zip::setErrorHandler( &subroutine )"
.PD 0
.IP "Archive::Zip::setErrorHandler( { subroutine => \e&subroutine } )" 4
.IX Item "Archive::Zip::setErrorHandler( { subroutine => &subroutine } )"
.PD
Change the subroutine called with error strings. This
defaults to \e&Carp::carp, but you may want to change it to
get the error strings. This is not exportable, so you must
call it like:
.Sp
.Vb 1
\&    Archive::Zip::setErrorHandler( \e&myErrorHandler );
.Ve
.Sp
If myErrorHandler is undef, resets handler to default.
Returns old error handler. Note that if you call Carp::carp
or a similar routine or if you're chaining to the default
error handler from your error handler, you may want to
increment the number of caller levels that are skipped (do
not just set it to a number):
.Sp
.Vb 1
\&    $Carp::CarpLevel++;
.Ve
.ie n .IP "Archive::Zip::tempFile( [ $tmpdir ] )" 4
.el .IP "Archive::Zip::tempFile( [ \f(CW$tmpdir\fR ] )" 4
.IX Item "Archive::Zip::tempFile( [ $tmpdir ] )"
.PD 0
.ie n .IP "Archive::Zip::tempFile( { tempDir => $tmpdir } )" 4
.el .IP "Archive::Zip::tempFile( { tempDir => \f(CW$tmpdir\fR } )" 4
.IX Item "Archive::Zip::tempFile( { tempDir => $tmpdir } )"
.PD
Create a uniquely named temp file. It will be returned open
for read/write. If \f(CW$tmpdir\fR is given, it is used as the
name of a directory to create the file in. If not given,
creates the file using \f(CW\*(C`File::Spec::tmpdir()\*(C'\fR. Generally, you can
override this choice using the
.Sp
.Vb 1
\&    $ENV{TMPDIR}
.Ve
.Sp
environment variable. But see the File::Spec
documentation for your system. Note that on many systems, if you're
running in taint mode, then you must make sure that \f(CW$ENV{TMPDIR}\fR is
untainted for it to be used.
Will \fI\s-1NOT\s0\fR create \f(CW$tmpdir\fR if it does not exist (this is a change
from prior versions!). Returns file handle and name:
.Sp
.Vb 3
\&    my ($fh, $name) = Archive::Zip::tempFile();
\&    my ($fh, $name) = Archive::Zip::tempFile(\*(AqmyTempDir\*(Aq);
\&    my $fh = Archive::Zip::tempFile();  # if you don\*(Aqt need the name
.Ve
.SS "Zip Archive Accessors"
.IX Subsection "Zip Archive Accessors"
.IP "\fBmembers()\fR" 4
.IX Item "members()"
Return a copy of the members array
.Sp
.Vb 1
\&    my @members = $zip\->members();
.Ve
.IP "\fBnumberOfMembers()\fR" 4
.IX Item "numberOfMembers()"
Return the number of members I have
.IP "\fBmemberNames()\fR" 4
.IX Item "memberNames()"
Return a list of the (internal) file names of the zip members
.ie n .IP "memberNamed( $string )" 4
.el .IP "memberNamed( \f(CW$string\fR )" 4
.IX Item "memberNamed( $string )"
.PD 0
.ie n .IP "memberNamed( { zipName => $string } )" 4
.el .IP "memberNamed( { zipName => \f(CW$string\fR } )" 4
.IX Item "memberNamed( { zipName => $string } )"
.PD
Return ref to member whose filename equals given filename or
undef. \f(CW$string\fR must be in Zip (Unix) filename format.
.ie n .IP "membersMatching( $regex )" 4
.el .IP "membersMatching( \f(CW$regex\fR )" 4
.IX Item "membersMatching( $regex )"
.PD 0
.ie n .IP "membersMatching( { regex => $regex } )" 4
.el .IP "membersMatching( { regex => \f(CW$regex\fR } )" 4
.IX Item "membersMatching( { regex => $regex } )"
.PD
Return array of members whose filenames match given regular
expression in list context. Returns number of matching
members in scalar context.
.Sp
.Vb 3
\&    my @textFileMembers = $zip\->membersMatching( \*(Aq.*\e.txt\*(Aq );
\&    # or
\&    my $numberOfTextFiles = $zip\->membersMatching( \*(Aq.*\e.txt\*(Aq );
.Ve
.IP "\fBzip64()\fR" 4
.IX Item "zip64()"
Returns whether the previous read or write of the archive has
been done in zip64 format.
.IP "\fBdesiredZip64Mode()\fR" 4
.IX Item "desiredZip64Mode()"
Gets or sets which parts of the archive should be written in
zip64 format: All parts as needed (\s-1ZIP64_AS_NEEDED\s0), the default,
force writing the zip64 end of central directory record
(\s-1ZIP64_EOCD\s0), force writing the zip64 \s-1EOCD\s0 record and all headers
in zip64 format (\s-1ZIP64_HEADERS\s0).
.IP "\fBversionMadeBy()\fR" 4
.IX Item "versionMadeBy()"
.PD 0
.IP "\fBversionNeededToExtract()\fR" 4
.IX Item "versionNeededToExtract()"
.PD
Gets the fields from the zip64 end of central directory
record. These are always 0 if the archive is not in zip64 format.
.IP "\fBdiskNumber()\fR" 4
.IX Item "diskNumber()"
Return the disk that I start on. Not used for writing zips,
but might be interesting if you read a zip in. This should be
0, as Archive::Zip does not handle multi-volume archives.
.IP "\fBdiskNumberWithStartOfCentralDirectory()\fR" 4
.IX Item "diskNumberWithStartOfCentralDirectory()"
Return the disk number that holds the beginning of the
central directory. Not used for writing zips, but might be
interesting if you read a zip in. This should be 0, as
Archive::Zip does not handle multi-volume archives.
.IP "\fBnumberOfCentralDirectoriesOnThisDisk()\fR" 4
.IX Item "numberOfCentralDirectoriesOnThisDisk()"
Return the number of \s-1CD\s0 structures in the zipfile last read in.
Not used for writing zips, but might be interesting if you read a zip
in.
.IP "\fBnumberOfCentralDirectories()\fR" 4
.IX Item "numberOfCentralDirectories()"
Return the number of \s-1CD\s0 structures in the zipfile last read in.
Not used for writing zips, but might be interesting if you read a zip
in.
.IP "\fBcentralDirectorySize()\fR" 4
.IX Item "centralDirectorySize()"
Returns central directory size, as read from an external zip
file. Not used for writing zips, but might be interesting if
you read a zip in.
.IP "\fBcentralDirectoryOffsetWRTStartingDiskNumber()\fR" 4
.IX Item "centralDirectoryOffsetWRTStartingDiskNumber()"
Returns the offset into the zip file where the \s-1CD\s0 begins. Not
used for writing zips, but might be interesting if you read a
zip in.
.ie n .IP "zipfileComment( [ $string ] )" 4
.el .IP "zipfileComment( [ \f(CW$string\fR ] )" 4
.IX Item "zipfileComment( [ $string ] )"
.PD 0
.ie n .IP "zipfileComment( [ { comment => $string } ] )" 4
.el .IP "zipfileComment( [ { comment => \f(CW$string\fR } ] )" 4
.IX Item "zipfileComment( [ { comment => $string } ] )"
.PD
Get or set the zipfile comment. Returns the old comment.
.Sp
.Vb 2
\&    print $zip\->zipfileComment();
\&    $zip\->zipfileComment( \*(AqNew Comment\*(Aq );
.Ve
.IP "\fBeocdOffset()\fR" 4
.IX Item "eocdOffset()"
Returns the (unexpected) number of bytes between where the
\&\s-1EOCD\s0 was found and where it expected to be. This is normally
0, but would be positive if something (a virus, perhaps) had
added bytes somewhere before the \s-1EOCD.\s0 Not used for writing
zips, but might be interesting if you read a zip in. Here is
an example of how you can diagnose this:
.Sp
.Vb 5
\&  my $zip = Archive::Zip\->new(\*(Aqsomefile.zip\*(Aq);
\&  if ($zip\->eocdOffset())
\&  {
\&    warn "A virus has added ", $zip\->eocdOffset, " bytes of garbage\en";
\&  }
.Ve
.Sp
The \f(CW\*(C`eocdOffset()\*(C'\fR is used to adjust the starting position of member
headers, if necessary.
.IP "\fBfileName()\fR" 4
.IX Item "fileName()"
Returns the name of the file last read from. If nothing has
been read yet, returns an empty string; if read from a file
handle, returns the handle in string form.
.SS "Zip Archive Member Operations"
.IX Subsection "Zip Archive Member Operations"
Various operations on a zip file modify members. When a member is
passed as an argument, you can either use a reference to the member
itself, or the name of a member. Of course, using the name requires
that names be unique within a zip (this is not enforced).
.ie n .IP "removeMember( $memberOrName )" 4
.el .IP "removeMember( \f(CW$memberOrName\fR )" 4
.IX Item "removeMember( $memberOrName )"
.PD 0
.ie n .IP "removeMember( { memberOrZipName => $memberOrName } )" 4
.el .IP "removeMember( { memberOrZipName => \f(CW$memberOrName\fR } )" 4
.IX Item "removeMember( { memberOrZipName => $memberOrName } )"
.PD
Remove and return the given member, or match its name and
remove it. Returns undef if member or name does not exist in this
Zip. No-op if member does not belong to this zip.
.ie n .IP "replaceMember( $memberOrName, $newMember )" 4
.el .IP "replaceMember( \f(CW$memberOrName\fR, \f(CW$newMember\fR )" 4
.IX Item "replaceMember( $memberOrName, $newMember )"
.PD 0
.ie n .IP "replaceMember( { memberOrZipName => $memberOrName, newMember => $newMember } )" 4
.el .IP "replaceMember( { memberOrZipName => \f(CW$memberOrName\fR, newMember => \f(CW$newMember\fR } )" 4
.IX Item "replaceMember( { memberOrZipName => $memberOrName, newMember => $newMember } )"
.PD
Remove and return the given member, or match its name and
remove it. Replace with new member. Returns undef if member or
name does not exist in this Zip, or if \f(CW$newMember\fR is undefined.
.Sp
It is an (undiagnosed) error to provide a \f(CW$newMember\fR that is a
member of the zip being modified.
.Sp
.Vb 4
\&    my $member1 = $zip\->removeMember( \*(Aqxyz\*(Aq );
\&    my $member2 = $zip\->replaceMember( \*(Aqabc\*(Aq, $member1 );
\&    # now, $member2 (named \*(Aqabc\*(Aq) is not in $zip,
\&    # and $member1 (named \*(Aqxyz\*(Aq) is, having taken $member2\*(Aqs place.
.Ve
.ie n .IP "extractMember( $memberOrName [, $extractedName ] )" 4
.el .IP "extractMember( \f(CW$memberOrName\fR [, \f(CW$extractedName\fR ] )" 4
.IX Item "extractMember( $memberOrName [, $extractedName ] )"
.PD 0
.ie n .IP "extractMember( { memberOrZipName => $memberOrName [, name => $extractedName ] } )" 4
.el .IP "extractMember( { memberOrZipName => \f(CW$memberOrName\fR [, name => \f(CW$extractedName\fR ] } )" 4
.IX Item "extractMember( { memberOrZipName => $memberOrName [, name => $extractedName ] } )"
.PD
Extract the given member, or match its name and extract it.
Returns undef if member does not exist in this Zip. If
optional second arg is given, use it as the name of the
extracted member. Otherwise, the internal filename of the
member is used as the name of the extracted file or
directory.
If you pass \f(CW$extractedName\fR, it should be in the local file
system's format.
If you do not pass \f(CW$extractedName\fR and the internal filename traverses
a parent directory or a symbolic link, the extraction will be aborted with
\&\f(CW\*(C`AC_ERROR\*(C'\fR for security reason.
All necessary directories will be created. Returns \f(CW\*(C`AZ_OK\*(C'\fR
on success.
.ie n .IP "extractMemberWithoutPaths( $memberOrName [, $extractedName ] )" 4
.el .IP "extractMemberWithoutPaths( \f(CW$memberOrName\fR [, \f(CW$extractedName\fR ] )" 4
.IX Item "extractMemberWithoutPaths( $memberOrName [, $extractedName ] )"
.PD 0
.ie n .IP "extractMemberWithoutPaths( { memberOrZipName => $memberOrName [, name => $extractedName ] } )" 4
.el .IP "extractMemberWithoutPaths( { memberOrZipName => \f(CW$memberOrName\fR [, name => \f(CW$extractedName\fR ] } )" 4
.IX Item "extractMemberWithoutPaths( { memberOrZipName => $memberOrName [, name => $extractedName ] } )"
.PD
Extract the given member, or match its name and extract it.
Does not use path information (extracts into the current
directory). Returns undef if member does not exist in this
Zip.
If optional second arg is given, use it as the name of the
extracted member (its paths will be deleted too). Otherwise,
the internal filename of the member (minus paths) is used as
the name of the extracted file or directory. Returns \f(CW\*(C`AZ_OK\*(C'\fR
on success.
If you do not pass \f(CW$extractedName\fR and the internal filename is equalled
to a local symbolic link, the extraction will be aborted with \f(CW\*(C`AC_ERROR\*(C'\fR for
security reason.
.ie n .IP "addMember( $member )" 4
.el .IP "addMember( \f(CW$member\fR )" 4
.IX Item "addMember( $member )"
.PD 0
.ie n .IP "addMember( { member => $member } )" 4
.el .IP "addMember( { member => \f(CW$member\fR } )" 4
.IX Item "addMember( { member => $member } )"
.PD
Append a member (possibly from another zip file) to the zip
file. Returns the new member. Generally, you will use
\&\fBaddFile()\fR, \fBaddDirectory()\fR, \fBaddFileOrDirectory()\fR, \fBaddString()\fR,
or \fBread()\fR to add members.
.Sp
.Vb 3
\&    # Move member named \*(Aqabc\*(Aq to end of zip:
\&    my $member = $zip\->removeMember( \*(Aqabc\*(Aq );
\&    $zip\->addMember( $member );
.Ve
.ie n .IP "updateMember( $memberOrName, $fileName )" 4
.el .IP "updateMember( \f(CW$memberOrName\fR, \f(CW$fileName\fR )" 4
.IX Item "updateMember( $memberOrName, $fileName )"
.PD 0
.ie n .IP "updateMember( { memberOrZipName => $memberOrName, name => $fileName } )" 4
.el .IP "updateMember( { memberOrZipName => \f(CW$memberOrName\fR, name => \f(CW$fileName\fR } )" 4
.IX Item "updateMember( { memberOrZipName => $memberOrName, name => $fileName } )"
.PD
Update a single member from the file or directory named \f(CW$fileName\fR.
Returns the (possibly added or updated) member, if any; \f(CW\*(C`undef\*(C'\fR on
errors.
The comparison is based on \f(CW\*(C`lastModTime()\*(C'\fR and (in the case of a
non-directory) the size of the file.
.ie n .IP "addFile( $fileName [, $newName, $compressionLevel ] )" 4
.el .IP "addFile( \f(CW$fileName\fR [, \f(CW$newName\fR, \f(CW$compressionLevel\fR ] )" 4
.IX Item "addFile( $fileName [, $newName, $compressionLevel ] )"
.PD 0
.ie n .IP "addFile( { filename => $fileName [, zipName => $newName, compressionLevel => $compressionLevel } ] )" 4
.el .IP "addFile( { filename => \f(CW$fileName\fR [, zipName => \f(CW$newName\fR, compressionLevel => \f(CW$compressionLevel\fR } ] )" 4
.IX Item "addFile( { filename => $fileName [, zipName => $newName, compressionLevel => $compressionLevel } ] )"
.PD
Append a member whose data comes from an external file,
returning the member or undef. The member will have its file
name set to the name of the external file, and its
desiredCompressionMethod set to \s-1COMPRESSION_DEFLATED.\s0 The
file attributes and last modification time will be set from
the file.
If the name given does not represent a readable plain file or
symbolic link, undef will be returned. \f(CW$fileName\fR must be
in the format required for the local file system.
The optional \f(CW$newName\fR argument sets the internal file name
to something different than the given \f(CW$fileName\fR. \f(CW$newName\fR,
if given, must be in Zip name format (i.e. Unix).
The text mode bit will be set if the contents appears to be
text (as returned by the \f(CW\*(C`\-T\*(C'\fR perl operator).
.Sp
\&\fI\s-1NOTE\s0\fR that you should not (generally) use absolute path names
in zip member names, as this will cause problems with some zip
tools as well as introduce a security hole and make the zip
harder to use.
.ie n .IP "addDirectory( $directoryName [, $fileName ] )" 4
.el .IP "addDirectory( \f(CW$directoryName\fR [, \f(CW$fileName\fR ] )" 4
.IX Item "addDirectory( $directoryName [, $fileName ] )"
.PD 0
.ie n .IP "addDirectory( { directoryName => $directoryName [, zipName => $fileName ] } )" 4
.el .IP "addDirectory( { directoryName => \f(CW$directoryName\fR [, zipName => \f(CW$fileName\fR ] } )" 4
.IX Item "addDirectory( { directoryName => $directoryName [, zipName => $fileName ] } )"
.PD
Append a member created from the given directory name. The
directory name does not have to name an existing directory.
If the named directory exists, the file modification time and
permissions are set from the existing directory, otherwise
they are set to now and permissive default permissions.
\&\f(CW$directoryName\fR must be in local file system format.
The optional second argument sets the name of the archive
member (which defaults to \f(CW$directoryName\fR). If given, it
must be in Zip (Unix) format.
Returns the new member.
.ie n .IP "addFileOrDirectory( $name [, $newName, $compressionLevel ] )" 4
.el .IP "addFileOrDirectory( \f(CW$name\fR [, \f(CW$newName\fR, \f(CW$compressionLevel\fR ] )" 4
.IX Item "addFileOrDirectory( $name [, $newName, $compressionLevel ] )"
.PD 0
.ie n .IP "addFileOrDirectory( { name => $name [, zipName => $newName, compressionLevel => $compressionLevel ] } )" 4
.el .IP "addFileOrDirectory( { name => \f(CW$name\fR [, zipName => \f(CW$newName\fR, compressionLevel => \f(CW$compressionLevel\fR ] } )" 4
.IX Item "addFileOrDirectory( { name => $name [, zipName => $newName, compressionLevel => $compressionLevel ] } )"
.PD
Append a member from the file or directory named \f(CW$name\fR. If
\&\f(CW$newName\fR is given, use it for the name of the new member.
Will add or remove trailing slashes from \f(CW$newName\fR as needed.
\&\f(CW$name\fR must be in local file system format.
The optional second argument sets the name of the archive
member (which defaults to \f(CW$name\fR). If given, it must be in
Zip (Unix) format.
.ie n .IP "addString( $stringOrStringRef, $name, [$compressionLevel] )" 4
.el .IP "addString( \f(CW$stringOrStringRef\fR, \f(CW$name\fR, [$compressionLevel] )" 4
.IX Item "addString( $stringOrStringRef, $name, [$compressionLevel] )"
.PD 0
.ie n .IP "addString( { string => $stringOrStringRef [, zipName => $name, compressionLevel => $compressionLevel ] } )" 4
.el .IP "addString( { string => \f(CW$stringOrStringRef\fR [, zipName => \f(CW$name\fR, compressionLevel => \f(CW$compressionLevel\fR ] } )" 4
.IX Item "addString( { string => $stringOrStringRef [, zipName => $name, compressionLevel => $compressionLevel ] } )"
.PD
Append a member created from the given string or string
reference. The name is given by the second argument.
Returns the new member. The last modification time will be
set to now, and the file attributes will be set to permissive
defaults.
.Sp
.Vb 1
\&    my $member = $zip\->addString( \*(AqThis is a test\*(Aq, \*(Aqtest.txt\*(Aq );
.Ve
.ie n .IP "contents( $memberOrMemberName [, $newContents ] )" 4
.el .IP "contents( \f(CW$memberOrMemberName\fR [, \f(CW$newContents\fR ] )" 4
.IX Item "contents( $memberOrMemberName [, $newContents ] )"
.PD 0
.ie n .IP "contents( { memberOrZipName => $memberOrMemberName [, contents => $newContents ] } )" 4
.el .IP "contents( { memberOrZipName => \f(CW$memberOrMemberName\fR [, contents => \f(CW$newContents\fR ] } )" 4
.IX Item "contents( { memberOrZipName => $memberOrMemberName [, contents => $newContents ] } )"
.PD
Returns the uncompressed data for a particular member, or
undef.
.Sp
.Vb 1
\&    print "xyz.txt contains " . $zip\->contents( \*(Aqxyz.txt\*(Aq );
.Ve
.Sp
Also can change the contents of a member:
.Sp
.Vb 1
\&    $zip\->contents( \*(Aqxyz.txt\*(Aq, \*(AqThis is the new contents\*(Aq );
.Ve
.Sp
If called expecting an array as the return value, it will include
the status as the second value in the array.
.Sp
.Vb 1
\&    ($content, $status) = $zip\->contents( \*(Aqxyz.txt\*(Aq);
.Ve
.SS "Zip Archive I/O operations"
.IX Subsection "Zip Archive I/O operations"
A Zip archive can be written to a file or file handle, or read from
one.
.ie n .IP "writeToFileNamed( $fileName )" 4
.el .IP "writeToFileNamed( \f(CW$fileName\fR )" 4
.IX Item "writeToFileNamed( $fileName )"
.PD 0
.ie n .IP "writeToFileNamed( { fileName => $fileName } )" 4
.el .IP "writeToFileNamed( { fileName => \f(CW$fileName\fR } )" 4
.IX Item "writeToFileNamed( { fileName => $fileName } )"
.PD
Write a zip archive to named file. Returns \f(CW\*(C`AZ_OK\*(C'\fR on
success.
.Sp
.Vb 2
\&    my $status = $zip\->writeToFileNamed( \*(Aqxx.zip\*(Aq );
\&    die "error somewhere" if $status != AZ_OK;
.Ve
.Sp
Note that if you use the same name as an existing zip file
that you read in, you will clobber ZipFileMembers. So
instead, write to a different file name, then delete the
original.
If you use the \f(CW\*(C`overwrite()\*(C'\fR or \f(CW\*(C`overwriteAs()\*(C'\fR methods, you can
re-write the original zip in this way.
\&\f(CW$fileName\fR should be a valid file name on your system.
.ie n .IP "writeToFileHandle( $fileHandle [, $seekable] )" 4
.el .IP "writeToFileHandle( \f(CW$fileHandle\fR [, \f(CW$seekable\fR] )" 4
.IX Item "writeToFileHandle( $fileHandle [, $seekable] )"
Write a zip archive to a file handle. Return \s-1AZ_OK\s0 on
success. The optional second arg tells whether or not to try
to seek backwards to re-write headers. If not provided, it is
set if the Perl \f(CW\*(C`\-f\*(C'\fR test returns true. This could fail on
some operating systems, though.
.Sp
.Vb 4
\&    my $fh = IO::File\->new( \*(AqsomeFile.zip\*(Aq, \*(Aqw\*(Aq );
\&    unless ( $zip\->writeToFileHandle( $fh ) == AZ_OK ) {
\&        # error handling
\&    }
.Ve
.Sp
If you pass a file handle that is not seekable (like if
you're writing to a pipe or a socket), pass a false second
argument:
.Sp
.Vb 2
\&    my $fh = IO::File\->new( \*(Aq| cat > somefile.zip\*(Aq, \*(Aqw\*(Aq );
\&    $zip\->writeToFileHandle( $fh, 0 );   # fh is not seekable
.Ve
.Sp
If this method fails during the write of a member, that
member and all following it will return false from
\&\f(CW\*(C`wasWritten()\*(C'\fR. See \fBwriteCentralDirectory()\fR for a way to
deal with this.
If you want, you can write data to the file handle before
passing it to \fBwriteToFileHandle()\fR; this could be used (for
instance) for making self-extracting archives. However, this
only works reliably when writing to a real file (as opposed
to \s-1STDOUT\s0 or some other possible non-file).
.Sp
See examples/selfex.pl for how to write a self-extracting
archive.
.ie n .IP "writeCentralDirectory( $fileHandle [, $offset ] )" 4
.el .IP "writeCentralDirectory( \f(CW$fileHandle\fR [, \f(CW$offset\fR ] )" 4
.IX Item "writeCentralDirectory( $fileHandle [, $offset ] )"
.PD 0
.ie n .IP "writeCentralDirectory( { fileHandle => $fileHandle [, offset => $offset ] } )" 4
.el .IP "writeCentralDirectory( { fileHandle => \f(CW$fileHandle\fR [, offset => \f(CW$offset\fR ] } )" 4
.IX Item "writeCentralDirectory( { fileHandle => $fileHandle [, offset => $offset ] } )"
.PD
Writes the central directory structure to the given file
handle.
.Sp
Returns \s-1AZ_OK\s0 on success. If given an \f(CW$offset\fR, will
seek to that point before writing. This can be used for
recovery in cases where writeToFileHandle or writeToFileNamed
returns an \s-1IO\s0 error because of running out of space on the
destination file.
.Sp
You can truncate the zip by seeking backwards and then writing the
directory:
.Sp
.Vb 10
\&    my $fh = IO::File\->new( \*(AqsomeFile.zip\*(Aq, \*(Aqw\*(Aq );
\&        my $retval = $zip\->writeToFileHandle( $fh );
\&    if ( $retval == AZ_IO_ERROR ) {
\&        my @unwritten = grep { not $_\->wasWritten() } $zip\->members();
\&        if (@unwritten) {
\&            $zip\->removeMember( $member ) foreach my $member ( @unwritten );
\&            $zip\->writeCentralDirectory( $fh,
\&            $unwritten[0]\->writeLocalHeaderRelativeOffset());
\&        }
\&    }
.Ve
.ie n .IP "overwriteAs( $newName )" 4
.el .IP "overwriteAs( \f(CW$newName\fR )" 4
.IX Item "overwriteAs( $newName )"
.PD 0
.ie n .IP "overwriteAs( { filename => $newName } )" 4
.el .IP "overwriteAs( { filename => \f(CW$newName\fR } )" 4
.IX Item "overwriteAs( { filename => $newName } )"
.PD
Write the zip to the specified file, as safely as possible.
This is done by first writing to a temp file, then renaming
the original if it exists, then renaming the temp file, then
deleting the renamed original if it exists. Returns \s-1AZ_OK\s0 if
successful.
.IP "\fBoverwrite()\fR" 4
.IX Item "overwrite()"
Write back to the original zip file. See \fBoverwriteAs()\fR above.
If the zip was not ever read from a file, this generates an
error.
.ie n .IP "read( $fileName )" 4
.el .IP "read( \f(CW$fileName\fR )" 4
.IX Item "read( $fileName )"
.PD 0
.ie n .IP "read( { filename => $fileName } )" 4
.el .IP "read( { filename => \f(CW$fileName\fR } )" 4
.IX Item "read( { filename => $fileName } )"
.PD
Read zipfile headers from a zip file, appending new members.
Returns \f(CW\*(C`AZ_OK\*(C'\fR or error code.
.Sp
.Vb 2
\&    my $zipFile = Archive::Zip\->new();
\&    my $status = $zipFile\->read( \*(Aq/some/FileName.zip\*(Aq );
.Ve
.ie n .IP "readFromFileHandle( $fileHandle, $filename )" 4
.el .IP "readFromFileHandle( \f(CW$fileHandle\fR, \f(CW$filename\fR )" 4
.IX Item "readFromFileHandle( $fileHandle, $filename )"
.PD 0
.ie n .IP "readFromFileHandle( { fileHandle => $fileHandle, filename => $filename } )" 4
.el .IP "readFromFileHandle( { fileHandle => \f(CW$fileHandle\fR, filename => \f(CW$filename\fR } )" 4
.IX Item "readFromFileHandle( { fileHandle => $fileHandle, filename => $filename } )"
.PD
Read zipfile headers from an already-opened file handle,
appending new members. Does not close the file handle.
Returns \f(CW\*(C`AZ_OK\*(C'\fR or error code. Note that this requires a
seekable file handle; reading from a stream is not yet
supported, but using in-memory data is.
.Sp
.Vb 5
\&    my $fh = IO::File\->new( \*(Aq/some/FileName.zip\*(Aq, \*(Aqr\*(Aq );
\&    my $zip1 = Archive::Zip\->new();
\&    my $status = $zip1\->readFromFileHandle( $fh );
\&    my $zip2 = Archive::Zip\->new();
\&    $status = $zip2\->readFromFileHandle( $fh );
.Ve
.Sp
Read zip using in-memory data (recursable):
.Sp
.Vb 5
\&    open my $fh, "<", "archive.zip" or die $!;
\&    my $zip_data = do { local $.; <$fh> };
\&    my $zip = Archive::Zip\->new;
\&    open my $dh, "+<", \e$zip_data;
\&    $zip\->readFromFileHandle ($dh);
.Ve
.SS "Zip Archive Tree operations"
.IX Subsection "Zip Archive Tree operations"
These used to be in Archive::Zip::Tree but got moved into
Archive::Zip. They enable operation on an entire tree of members or
files.
A usage example:
.PP
.Vb 2
\&  use Archive::Zip;
\&  my $zip = Archive::Zip\->new();
\&
\&  # add all readable files and directories below . as xyz/*
\&  $zip\->addTree( \*(Aq.\*(Aq, \*(Aqxyz\*(Aq );
\&
\&  # add all readable plain files below /abc as def/*
\&  $zip\->addTree( \*(Aq/abc\*(Aq, \*(Aqdef\*(Aq, sub { \-f && \-r } );
\&
\&  # add all .c files below /tmp as stuff/*
\&  $zip\->addTreeMatching( \*(Aq/tmp\*(Aq, \*(Aqstuff\*(Aq, \*(Aq\e.c$\*(Aq );
\&
\&  # add all .o files below /tmp as stuff/* if they aren\*(Aqt writable
\&  $zip\->addTreeMatching( \*(Aq/tmp\*(Aq, \*(Aqstuff\*(Aq, \*(Aq\e.o$\*(Aq, sub { ! \-w } );
\&
\&  # add all .so files below /tmp that are smaller than 200 bytes as stuff/*
\&  $zip\->addTreeMatching( \*(Aq/tmp\*(Aq, \*(Aqstuff\*(Aq, \*(Aq\e.o$\*(Aq, sub { \-s < 200 } );
\&
\&  # and write them into a file
\&  $zip\->writeToFileNamed(\*(Aqxxx.zip\*(Aq);
\&
\&  # now extract the same files into /tmpx
\&  $zip\->extractTree( \*(Aqstuff\*(Aq, \*(Aq/tmpx\*(Aq );
.Ve
.ie n .IP "$zip\->addTree( $root, $dest [, $pred, $compressionLevel ] ) \*(-- Add tree of files to a zip" 4
.el .IP "\f(CW$zip\fR\->addTree( \f(CW$root\fR, \f(CW$dest\fR [, \f(CW$pred\fR, \f(CW$compressionLevel\fR ] ) \*(-- Add tree of files to a zip" 4
.IX Item "$zip->addTree( $root, $dest [, $pred, $compressionLevel ] ) Add tree of files to a zip"
.PD 0
.ie n .IP "$zip\->addTree( { root => $root, zipName => $dest [, select => $pred, compressionLevel => $compressionLevel ] )" 4
.el .IP "\f(CW$zip\fR\->addTree( { root => \f(CW$root\fR, zipName => \f(CW$dest\fR [, select => \f(CW$pred\fR, compressionLevel => \f(CW$compressionLevel\fR ] )" 4
.IX Item "$zip->addTree( { root => $root, zipName => $dest [, select => $pred, compressionLevel => $compressionLevel ] )"
.PD
\&\f(CW$root\fR is the root of the tree of files and directories to be
added. It is a valid directory name on your system. \f(CW$dest\fR is
the name for the root in the zip file (undef or blank means
to use relative pathnames). It is a valid \s-1ZIP\s0 directory name
(that is, it uses forward slashes (/) for separating
directory components). \f(CW$pred\fR is an optional subroutine
reference to select files: it is passed the name of the
prospective file or directory using \f(CW$_\fR, and if it returns
true, the file or directory will be included. The default is
to add all readable files and directories. For instance,
using
.Sp
.Vb 2
\&  my $pred = sub { /\e.txt/ };
\&  $zip\->addTree( \*(Aq.\*(Aq, \*(Aq\*(Aq, $pred );
.Ve
.Sp
will add all the .txt files in and below the current
directory, using relative names, and making the names
identical in the zipfile:
.Sp
.Vb 4
\&  original name           zip member name
\&  ./xyz                   xyz
\&  ./a/                    a/
\&  ./a/b                   a/b
.Ve
.Sp
To translate absolute to relative pathnames, just pass them
in: \f(CW$zip\fR\->addTree( '/c/d', 'a' );
.Sp
.Vb 4
\&  original name           zip member name
\&  /c/d/xyz                a/xyz
\&  /c/d/a/                 a/a/
\&  /c/d/a/b                a/a/b
.Ve
.Sp
Returns \s-1AZ_OK\s0 on success. Note that this will not follow
symbolic links to directories. Note also that this does not
check for the validity of filenames.
.Sp
Note that you generally \fIdon't\fR want to make zip archive member names
absolute.
.ie n .IP "$zip\->addTreeMatching( $root, $dest, $pattern [, $pred, $compressionLevel ] )" 4
.el .IP "\f(CW$zip\fR\->addTreeMatching( \f(CW$root\fR, \f(CW$dest\fR, \f(CW$pattern\fR [, \f(CW$pred\fR, \f(CW$compressionLevel\fR ] )" 4
.IX Item "$zip->addTreeMatching( $root, $dest, $pattern [, $pred, $compressionLevel ] )"
.PD 0
.ie n .IP "$zip\->addTreeMatching( { root => $root, zipName => $dest, pattern => $pattern [, select => $pred, compressionLevel => $compressionLevel ] } )" 4
.el .IP "\f(CW$zip\fR\->addTreeMatching( { root => \f(CW$root\fR, zipName => \f(CW$dest\fR, pattern => \f(CW$pattern\fR [, select => \f(CW$pred\fR, compressionLevel => \f(CW$compressionLevel\fR ] } )" 4
.IX Item "$zip->addTreeMatching( { root => $root, zipName => $dest, pattern => $pattern [, select => $pred, compressionLevel => $compressionLevel ] } )"
.PD
\&\f(CW$root\fR is the root of the tree of files and directories to be
added \f(CW$dest\fR is the name for the root in the zip file (undef
means to use relative pathnames) \f(CW$pattern\fR is a (non-anchored)
regular expression for filenames to match \f(CW$pred\fR is an
optional subroutine reference to select files: it is passed
the name of the prospective file or directory in \f(CW$_\fR, and
if it returns true, the file or directory will be included.
The default is to add all readable files and directories. To
add all files in and below the current directory whose names
end in \f(CW\*(C`.pl\*(C'\fR, and make them extract into a subdirectory
named \f(CW\*(C`xyz\*(C'\fR, do this:
.Sp
.Vb 1
\&  $zip\->addTreeMatching( \*(Aq.\*(Aq, \*(Aqxyz\*(Aq, \*(Aq\e.pl$\*(Aq )
.Ve
.Sp
To add all \fIwritable\fR files in and below the directory named
\&\f(CW\*(C`/abc\*(C'\fR whose names end in \f(CW\*(C`.pl\*(C'\fR, and make them extract into
a subdirectory named \f(CW\*(C`xyz\*(C'\fR, do this:
.Sp
.Vb 1
\&  $zip\->addTreeMatching( \*(Aq/abc\*(Aq, \*(Aqxyz\*(Aq, \*(Aq\e.pl$\*(Aq, sub { \-w } )
.Ve
.Sp
Returns \s-1AZ_OK\s0 on success. Note that this will not follow
symbolic links to directories.
.ie n .IP "$zip\->updateTree( $root [, $dest , $pred , $mirror, $compressionLevel ] );" 4
.el .IP "\f(CW$zip\fR\->updateTree( \f(CW$root\fR [, \f(CW$dest\fR , \f(CW$pred\fR , \f(CW$mirror\fR, \f(CW$compressionLevel\fR ] );" 4
.IX Item "$zip->updateTree( $root [, $dest , $pred , $mirror, $compressionLevel ] );"
.PD 0
.ie n .IP "$zip\->updateTree( { root => $root [, zipName => $dest, select => $pred, mirror => $mirror, compressionLevel => $compressionLevel ] } );" 4
.el .IP "\f(CW$zip\fR\->updateTree( { root => \f(CW$root\fR [, zipName => \f(CW$dest\fR, select => \f(CW$pred\fR, mirror => \f(CW$mirror\fR, compressionLevel => \f(CW$compressionLevel\fR ] } );" 4
.IX Item "$zip->updateTree( { root => $root [, zipName => $dest, select => $pred, mirror => $mirror, compressionLevel => $compressionLevel ] } );"
.PD
Update a zip file from a directory tree.
.Sp
\&\f(CW\*(C`updateTree()\*(C'\fR takes the same arguments as \f(CW\*(C`addTree()\*(C'\fR, but first
checks to see whether the file or directory already exists in the zip
file, and whether it has been changed.
.Sp
If the fourth argument \f(CW$mirror\fR is true, then delete all my members
if corresponding files were not found.
.Sp
Returns an error code or \s-1AZ_OK\s0 if all is well.
.ie n .IP "$zip\->extractTree( [ $root, $dest, $volume } ] )" 4
.el .IP "\f(CW$zip\fR\->extractTree( [ \f(CW$root\fR, \f(CW$dest\fR, \f(CW$volume\fR } ] )" 4
.IX Item "$zip->extractTree( [ $root, $dest, $volume } ] )"
.PD 0
.ie n .IP "$zip\->extractTree( [ { root => $root, zipName => $dest, volume => $volume } ] )" 4
.el .IP "\f(CW$zip\fR\->extractTree( [ { root => \f(CW$root\fR, zipName => \f(CW$dest\fR, volume => \f(CW$volume\fR } ] )" 4
.IX Item "$zip->extractTree( [ { root => $root, zipName => $dest, volume => $volume } ] )"
.PD
If you don't give any arguments at all, will extract all the
files in the zip with their original names.
.Sp
If you supply one argument for \f(CW$root\fR, \f(CW\*(C`extractTree\*(C'\fR will extract
all the members whose names start with \f(CW$root\fR into the current
directory, stripping off \f(CW$root\fR first.
\&\f(CW$root\fR is in Zip (Unix) format.
For instance,
.Sp
.Vb 1
\&  $zip\->extractTree( \*(Aqa\*(Aq );
.Ve
.Sp
when applied to a zip containing the files:
a/x a/b/c ax/d/e d/e will extract:
.Sp
a/x as ./x
.Sp
a/b/c as ./b/c
.Sp
If you give two arguments, \f(CW\*(C`extractTree\*(C'\fR extracts all the members
whose names start with \f(CW$root\fR. It will translate \f(CW$root\fR into
\&\f(CW$dest\fR to construct the destination file name.
\&\f(CW$root\fR and \f(CW$dest\fR are in Zip (Unix) format.
For instance,
.Sp
.Vb 1
\&   $zip\->extractTree( \*(Aqa\*(Aq, \*(Aqd/e\*(Aq );
.Ve
.Sp
when applied to a zip containing the files:
a/x a/b/c ax/d/e d/e will extract:
.Sp
a/x to d/e/x
.Sp
a/b/c to d/e/b/c and ignore ax/d/e and d/e
.Sp
If you give three arguments, \f(CW\*(C`extractTree\*(C'\fR extracts all the members
whose names start with \f(CW$root\fR. It will translate \f(CW$root\fR into
\&\f(CW$dest\fR to construct the destination file name, and then it will
convert to local file system format, using \f(CW$volume\fR as the name of
the destination volume.
.Sp
\&\f(CW$root\fR and \f(CW$dest\fR are in Zip (Unix) format.
.Sp
\&\f(CW$volume\fR is in local file system format.
.Sp
For instance, under Windows,
.Sp
.Vb 1
\&   $zip\->extractTree( \*(Aqa\*(Aq, \*(Aqd/e\*(Aq, \*(Aqf:\*(Aq );
.Ve
.Sp
when applied to a zip containing the files:
a/x a/b/c ax/d/e d/e will extract:
.Sp
a/x to f:d/e/x
.Sp
a/b/c to f:d/e/b/c and ignore ax/d/e and d/e
.Sp
If you want absolute paths (the prior example used paths relative to
the current directory on the destination volume, you can specify these
in \f(CW$dest\fR:
.Sp
.Vb 1
\&   $zip\->extractTree( \*(Aqa\*(Aq, \*(Aq/d/e\*(Aq, \*(Aqf:\*(Aq );
.Ve
.Sp
when applied to a zip containing the files:
a/x a/b/c ax/d/e d/e will extract:
.Sp
a/x to f:\ed\ee\ex
.Sp
a/b/c to f:\ed\ee\eb\ec and ignore ax/d/e and d/e
.Sp
If the path to the extracted file traverses a parent directory or a symbolic
link, the extraction will be aborted with \f(CW\*(C`AC_ERROR\*(C'\fR for security reason.
Returns an error code or \s-1AZ_OK\s0 if everything worked \s-1OK.\s0
.SH "Archive::Zip Global Variables"
.IX Header "Archive::Zip Global Variables"
.ie n .IP "$Archive::Zip::UNICODE" 4
.el .IP "\f(CW$Archive::Zip::UNICODE\fR" 4
.IX Item "$Archive::Zip::UNICODE"
This variable governs how Unicode file and directory names are added
to or extracted from an archive. If set, file and directory names are considered
to be \s-1UTF\-8\s0 encoded. This is \fI\s-1EXPERIMENTAL AND BUGGY\s0 (there are some edge cases
on Win32)\fR. Please report problems.
.Sp
.Vb 4
\&    {
\&        local $Archive::Zip::UNICODE = 1;
\&        $zip\->addFile(\*(AqDéjà vu.txt\*(Aq);
\&    }
.Ve
.SH "MEMBER OPERATIONS"
.IX Header "MEMBER OPERATIONS"
.SS "Member Class Methods"
.IX Subsection "Member Class Methods"
Several constructors allow you to construct members without adding
them to a zip archive. These work the same as the \fBaddFile()\fR,
\&\fBaddDirectory()\fR, and \fBaddString()\fR zip instance methods described above,
but they don't add the new members to a zip.
.ie n .IP "Archive::Zip::Member\->newFromString( $stringOrStringRef [, $fileName ] )" 4
.el .IP "Archive::Zip::Member\->newFromString( \f(CW$stringOrStringRef\fR [, \f(CW$fileName\fR ] )" 4
.IX Item "Archive::Zip::Member->newFromString( $stringOrStringRef [, $fileName ] )"
.PD 0
.ie n .IP "Archive::Zip::Member\->newFromString( { string => $stringOrStringRef [, zipName => $fileName ] )" 4
.el .IP "Archive::Zip::Member\->newFromString( { string => \f(CW$stringOrStringRef\fR [, zipName => \f(CW$fileName\fR ] )" 4
.IX Item "Archive::Zip::Member->newFromString( { string => $stringOrStringRef [, zipName => $fileName ] )"
.PD
Construct a new member from the given string. Returns undef
on error.
.Sp
.Vb 3
\&    my $member = Archive::Zip::Member\->newFromString( \*(AqThis is a test\*(Aq );
\&    my $member = Archive::Zip::Member\->newFromString( \*(AqThis is a test\*(Aq, \*(Aqtest.txt\*(Aq );
\&    my $member = Archive::Zip::Member\->newFromString( { string => \*(AqThis is a test\*(Aq, zipName => \*(Aqtest.txt\*(Aq } );
.Ve
.ie n .IP "newFromFile( $fileName [, $zipName ] )" 4
.el .IP "newFromFile( \f(CW$fileName\fR [, \f(CW$zipName\fR ] )" 4
.IX Item "newFromFile( $fileName [, $zipName ] )"
.PD 0
.ie n .IP "newFromFile( { filename => $fileName [, zipName => $zipName ] } )" 4
.el .IP "newFromFile( { filename => \f(CW$fileName\fR [, zipName => \f(CW$zipName\fR ] } )" 4
.IX Item "newFromFile( { filename => $fileName [, zipName => $zipName ] } )"
.PD
Construct a new member from the given file. Returns undef on
error.
.Sp
.Vb 1
\&    my $member = Archive::Zip::Member\->newFromFile( \*(Aqxyz.txt\*(Aq );
.Ve
.ie n .IP "newDirectoryNamed( $directoryName [, $zipname ] )" 4
.el .IP "newDirectoryNamed( \f(CW$directoryName\fR [, \f(CW$zipname\fR ] )" 4
.IX Item "newDirectoryNamed( $directoryName [, $zipname ] )"
.PD 0
.ie n .IP "newDirectoryNamed( { directoryName => $directoryName [, zipName => $zipname ] } )" 4
.el .IP "newDirectoryNamed( { directoryName => \f(CW$directoryName\fR [, zipName => \f(CW$zipname\fR ] } )" 4
.IX Item "newDirectoryNamed( { directoryName => $directoryName [, zipName => $zipname ] } )"
.PD
Construct a new member from the given directory.
\&\f(CW$directoryName\fR must be a valid name on your file system; it does not
have to exist.
.Sp
If given, \f(CW$zipname\fR will be the name of the zip member; it must be a
valid Zip (Unix) name. If not given, it will be converted from
\&\f(CW$directoryName\fR.
.Sp
Returns undef on error.
.Sp
.Vb 1
\&    my $member = Archive::Zip::Member\->newDirectoryNamed( \*(AqCVS/\*(Aq );
.Ve
.SS "Member Simple Accessors"
.IX Subsection "Member Simple Accessors"
These methods get (and/or set) member attribute values.
.PP
The zip64 format requires parts of the member data to be stored
in the so-called extra fields.  You cannot get nor set this zip64
data through the extra field accessors described in this section.
In fact, the low-level member methods ensure that the zip64 data
in the extra fields is handled completely transparently and
invisibly to the user when members are read or written.
.IP "\fBzip64()\fR" 4
.IX Item "zip64()"
Returns whether the previous read or write of the member has been
done in zip64 format.
.IP "\fBdesiredZip64Mode()\fR" 4
.IX Item "desiredZip64Mode()"
Gets or sets whether the member's headers should be written in
zip64 format: As needed (\s-1ZIP64_AS_NEEDED\s0), the default, or always
(\s-1ZIP64_HEADERS\s0).
.IP "\fBversionMadeBy()\fR" 4
.IX Item "versionMadeBy()"
Gets the field from the member header.
.ie n .IP "fileAttributeFormat( [ $format ] )" 4
.el .IP "fileAttributeFormat( [ \f(CW$format\fR ] )" 4
.IX Item "fileAttributeFormat( [ $format ] )"
.PD 0
.ie n .IP "fileAttributeFormat( [ { format => $format ] } )" 4
.el .IP "fileAttributeFormat( [ { format => \f(CW$format\fR ] } )" 4
.IX Item "fileAttributeFormat( [ { format => $format ] } )"
.PD
Gets or sets the field from the member header. These are
\&\f(CW\*(C`FA_*\*(C'\fR values.
.IP "\fBversionNeededToExtract()\fR" 4
.IX Item "versionNeededToExtract()"
Gets the field from the member header.
.IP "\fBbitFlag()\fR" 4
.IX Item "bitFlag()"
Gets the general purpose bit field from the member header.
This is where the \f(CW\*(C`GPBF_*\*(C'\fR bits live.
.IP "\fBcompressionMethod()\fR" 4
.IX Item "compressionMethod()"
Returns the member compression method. This is the method
that is currently being used to compress the member data.
This will be \s-1COMPRESSION_STORED\s0 for added string or file
members, or any of the \f(CW\*(C`COMPRESSION_*\*(C'\fR values for members
from a zip file. However, this module can only handle members
whose data is in \s-1COMPRESSION_STORED\s0 or \s-1COMPRESSION_DEFLATED\s0
format.
.ie n .IP "desiredCompressionMethod( [ $method ] )" 4
.el .IP "desiredCompressionMethod( [ \f(CW$method\fR ] )" 4
.IX Item "desiredCompressionMethod( [ $method ] )"
.PD 0
.ie n .IP "desiredCompressionMethod( [ { compressionMethod => $method } ] )" 4
.el .IP "desiredCompressionMethod( [ { compressionMethod => \f(CW$method\fR } ] )" 4
.IX Item "desiredCompressionMethod( [ { compressionMethod => $method } ] )"
.PD
Get or set the member's \f(CW\*(C`desiredCompressionMethod\*(C'\fR. This is
the compression method that will be used when the member is
written. Returns prior desiredCompressionMethod. Only
\&\s-1COMPRESSION_DEFLATED\s0 or \s-1COMPRESSION_STORED\s0 are valid
arguments. Changing to \s-1COMPRESSION_STORED\s0 will change the
member desiredCompressionLevel to 0; changing to
\&\s-1COMPRESSION_DEFLATED\s0 will change the member
desiredCompressionLevel to \s-1COMPRESSION_LEVEL_DEFAULT.\s0
.ie n .IP "desiredCompressionLevel( [ $level ] )" 4
.el .IP "desiredCompressionLevel( [ \f(CW$level\fR ] )" 4
.IX Item "desiredCompressionLevel( [ $level ] )"
.PD 0
.ie n .IP "desiredCompressionLevel( [ { compressionLevel => $level } ] )" 4
.el .IP "desiredCompressionLevel( [ { compressionLevel => \f(CW$level\fR } ] )" 4
.IX Item "desiredCompressionLevel( [ { compressionLevel => $level } ] )"
.PD
Get or set the member's desiredCompressionLevel This is the
method that will be used to write. Returns prior
desiredCompressionLevel. Valid arguments are 0 through 9,
\&\s-1COMPRESSION_LEVEL_NONE, COMPRESSION_LEVEL_DEFAULT,
COMPRESSION_LEVEL_BEST_COMPRESSION,\s0 and
\&\s-1COMPRESSION_LEVEL_FASTEST. 0\s0 or \s-1COMPRESSION_LEVEL_NONE\s0 will
change the desiredCompressionMethod to \s-1COMPRESSION_STORED.\s0
All other arguments will change the desiredCompressionMethod
to \s-1COMPRESSION_DEFLATED.\s0
.IP "\fBexternalFileName()\fR" 4
.IX Item "externalFileName()"
Return the member's external file name, if any, or undef.
.IP "\fBfileName()\fR" 4
.IX Item "fileName()"
Get or set the member's internal filename. Returns the
(possibly new) filename. Names will have backslashes
converted to forward slashes, and will have multiple
consecutive slashes converted to single ones.
.IP "\fBlastModFileDateTime()\fR" 4
.IX Item "lastModFileDateTime()"
Return the member's last modification date/time stamp in
MS-DOS format.
.IP "\fBlastModTime()\fR" 4
.IX Item "lastModTime()"
Return the member's last modification date/time stamp,
converted to unix localtime format.
.Sp
.Vb 1
\&    print "Mod Time: " . scalar( localtime( $member\->lastModTime() ) );
.Ve
.IP "\fBsetLastModFileDateTimeFromUnix()\fR" 4
.IX Item "setLastModFileDateTimeFromUnix()"
Set the member's lastModFileDateTime from the given unix
time.
.Sp
.Vb 1
\&    $member\->setLastModFileDateTimeFromUnix( time() );
.Ve
.IP "\fBinternalFileAttributes()\fR" 4
.IX Item "internalFileAttributes()"
Return the internal file attributes field from the zip
header. This is only set for members read from a zip file.
.IP "\fBexternalFileAttributes()\fR" 4
.IX Item "externalFileAttributes()"
Return member attributes as read from the \s-1ZIP\s0 file. Note that
these are \s-1NOT UNIX\s0!
.ie n .IP "unixFileAttributes( [ $newAttributes ] )" 4
.el .IP "unixFileAttributes( [ \f(CW$newAttributes\fR ] )" 4
.IX Item "unixFileAttributes( [ $newAttributes ] )"
.PD 0
.ie n .IP "unixFileAttributes( [ { attributes => $newAttributes } ] )" 4
.el .IP "unixFileAttributes( [ { attributes => \f(CW$newAttributes\fR } ] )" 4
.IX Item "unixFileAttributes( [ { attributes => $newAttributes } ] )"
.PD
Get or set the member's file attributes using \s-1UNIX\s0 file
attributes. Returns old attributes.
.Sp
.Vb 1
\&    my $oldAttribs = $member\->unixFileAttributes( 0666 );
.Ve
.Sp
Note that the return value has more than just the file
permissions, so you will have to mask off the lowest bits for
comparisons.
.ie n .IP "localExtraField( [ $newField ] )" 4
.el .IP "localExtraField( [ \f(CW$newField\fR ] )" 4
.IX Item "localExtraField( [ $newField ] )"
.PD 0
.ie n .IP "localExtraField( [ { field => $newField } ] )" 4
.el .IP "localExtraField( [ { field => \f(CW$newField\fR } ] )" 4
.IX Item "localExtraField( [ { field => $newField } ] )"
.PD
Gets or sets the extra field that was read from the local
header. The extra field must be in the proper format.  If it is
not or if the new field contains data related to the zip64
format, this method does not modify the extra field and returns
\&\s-1AZ_FORMAT_ERROR,\s0 otherwise it returns \s-1AZ_OK.\s0
.ie n .IP "cdExtraField( [ $newField ] )" 4
.el .IP "cdExtraField( [ \f(CW$newField\fR ] )" 4
.IX Item "cdExtraField( [ $newField ] )"
.PD 0
.ie n .IP "cdExtraField( [ { field => $newField } ] )" 4
.el .IP "cdExtraField( [ { field => \f(CW$newField\fR } ] )" 4
.IX Item "cdExtraField( [ { field => $newField } ] )"
.PD
Gets or sets the extra field that was read from the central
directory header. The extra field must be in the proper format.
If it is not or if the new field contains data related to the
zip64 format, this method does not modify the extra field and
returns \s-1AZ_FORMAT_ERROR,\s0 otherwise it returns \s-1AZ_OK.\s0
.IP "\fBextraFields()\fR" 4
.IX Item "extraFields()"
Return both local and \s-1CD\s0 extra fields, concatenated.
.ie n .IP "fileComment( [ $newComment ] )" 4
.el .IP "fileComment( [ \f(CW$newComment\fR ] )" 4
.IX Item "fileComment( [ $newComment ] )"
.PD 0
.ie n .IP "fileComment( [ { comment => $newComment } ] )" 4
.el .IP "fileComment( [ { comment => \f(CW$newComment\fR } ] )" 4
.IX Item "fileComment( [ { comment => $newComment } ] )"
.PD
Get or set the member's file comment.
.IP "\fBhasDataDescriptor()\fR" 4
.IX Item "hasDataDescriptor()"
Get or set the data descriptor flag. If this is set, the
local header will not necessarily have the correct data
sizes. Instead, a small structure will be stored at the end
of the member data with these values. This should be
transparent in normal operation.
.IP "\fBcrc32()\fR" 4
.IX Item "crc32()"
Return the \s-1CRC\-32\s0 value for this member. This will not be set
for members that were constructed from strings or external
files until after the member has been written.
.IP "\fBcrc32String()\fR" 4
.IX Item "crc32String()"
Return the \s-1CRC\-32\s0 value for this member as an 8 character
printable hex string. This will not be set for members that
were constructed from strings or external files until after
the member has been written.
.IP "\fBcompressedSize()\fR" 4
.IX Item "compressedSize()"
Return the compressed size for this member. This will not be
set for members that were constructed from strings or
external files until after the member has been written.
.IP "\fBuncompressedSize()\fR" 4
.IX Item "uncompressedSize()"
Return the uncompressed size for this member.
.ie n .IP "password( [ $password ] )" 4
.el .IP "password( [ \f(CW$password\fR ] )" 4
.IX Item "password( [ $password ] )"
Returns the password for this member to be used on decryption.
If \f(CW$password\fR is given, it will set the password for the decryption.
.IP "\fBisEncrypted()\fR" 4
.IX Item "isEncrypted()"
Return true if this member is encrypted. The Archive::Zip
module does not currently support creation of encrypted
members. Decryption works more or less like this:
.Sp
.Vb 5
\&  my $zip = Archive::Zip\->new;
\&  $zip\->read ("encrypted.zip");
\&  for my $m (map { $zip\->memberNamed ($_) } $zip\->memberNames) {
\&      $m\->password ("secret");
\&      $m\->contents;  # is "" when password was wrong
.Ve
.Sp
That shows that the password has to be set per member, and not per
archive. This might change in the future.
.ie n .IP "isTextFile( [ $flag ] )" 4
.el .IP "isTextFile( [ \f(CW$flag\fR ] )" 4
.IX Item "isTextFile( [ $flag ] )"
.PD 0
.ie n .IP "isTextFile( [ { flag => $flag } ] )" 4
.el .IP "isTextFile( [ { flag => \f(CW$flag\fR } ] )" 4
.IX Item "isTextFile( [ { flag => $flag } ] )"
.PD
Returns true if I am a text file. Also can set the status if
given an argument (then returns old state). Note that this
module does not currently do anything with this flag upon
extraction or storage. That is, bytes are stored in native
format whether or not they came from a text file.
.IP "\fBisBinaryFile()\fR" 4
.IX Item "isBinaryFile()"
Returns true if I am a binary file. Also can set the status
if given an argument (then returns old state). Note that this
module does not currently do anything with this flag upon
extraction or storage. That is, bytes are stored in native
format whether or not they came from a text file.
.ie n .IP "extractToFileNamed( $fileName )" 4
.el .IP "extractToFileNamed( \f(CW$fileName\fR )" 4
.IX Item "extractToFileNamed( $fileName )"
.PD 0
.ie n .IP "extractToFileNamed( { name => $fileName } )" 4
.el .IP "extractToFileNamed( { name => \f(CW$fileName\fR } )" 4
.IX Item "extractToFileNamed( { name => $fileName } )"
.PD
Extract me to a file with the given name. The file will be
created with default modes. Directories will be created as
needed.
The \f(CW$fileName\fR argument should be a valid file name on your
file system.
Returns \s-1AZ_OK\s0 on success.
.IP "\fBisDirectory()\fR" 4
.IX Item "isDirectory()"
Returns true if I am a directory.
.IP "\fBisSymbolicLink()\fR" 4
.IX Item "isSymbolicLink()"
Returns true if I am a symbolic link.
.IP "\fBwriteLocalHeaderRelativeOffset()\fR" 4
.IX Item "writeLocalHeaderRelativeOffset()"
Returns the file offset in bytes the last time I was written.
.IP "\fBwasWritten()\fR" 4
.IX Item "wasWritten()"
Returns true if I was successfully written. Reset at the
beginning of a write attempt.
.SS "Low-level member data reading"
.IX Subsection "Low-level member data reading"
It is possible to use lower-level routines to access member data
streams, rather than the extract* methods and \fBcontents()\fR. For
instance, here is how to print the uncompressed contents of a member
in chunks using these methods:
.PP
.Vb 10
\&    my ( $member, $status, $bufferRef );
\&    $member = $zip\->memberNamed( \*(Aqxyz.txt\*(Aq );
\&    $member\->desiredCompressionMethod( COMPRESSION_STORED );
\&    $status = $member\->rewindData();
\&    die "error $status" unless $status == AZ_OK;
\&    while ( ! $member\->readIsDone() )
\&    {
\&    ( $bufferRef, $status ) = $member\->readChunk();
\&    die "error $status"
\&                if $status != AZ_OK && $status != AZ_STREAM_END;
\&    # do something with $bufferRef:
\&    print $$bufferRef;
\&    }
\&    $member\->endRead();
.Ve
.ie n .IP "readChunk( [ $chunkSize ] )" 4
.el .IP "readChunk( [ \f(CW$chunkSize\fR ] )" 4
.IX Item "readChunk( [ $chunkSize ] )"
.PD 0
.ie n .IP "readChunk( [ { chunkSize => $chunkSize } ] )" 4
.el .IP "readChunk( [ { chunkSize => \f(CW$chunkSize\fR } ] )" 4
.IX Item "readChunk( [ { chunkSize => $chunkSize } ] )"
.PD
This reads the next chunk of given size from the member's
data stream and compresses or uncompresses it as necessary,
returning a reference to the bytes read and a status. If size
argument is not given, defaults to global set by
Archive::Zip::setChunkSize. Status is \s-1AZ_OK\s0 on success until
the last chunk, where it returns \s-1AZ_STREAM_END.\s0 Returns \f(CW\*(C`(
\&\e$bytes, $status)\*(C'\fR.
.Sp
.Vb 2
\&    my ( $outRef, $status ) = $self\->readChunk();
\&    print $$outRef if $status != AZ_OK && $status != AZ_STREAM_END;
.Ve
.IP "\fBrewindData()\fR" 4
.IX Item "rewindData()"
Rewind data and set up for reading data streams or writing
zip files. Can take options for \f(CW\*(C`inflateInit()\*(C'\fR or
\&\f(CW\*(C`deflateInit()\*(C'\fR, but this is not likely to be necessary.
Subclass overrides should call this method. Returns \f(CW\*(C`AZ_OK\*(C'\fR
on success.
.IP "\fBendRead()\fR" 4
.IX Item "endRead()"
Reset the read variables and free the inflater or deflater.
Must be called to close files, etc. Returns \s-1AZ_OK\s0 on success.
.IP "\fBreadIsDone()\fR" 4
.IX Item "readIsDone()"
Return true if the read has run out of data or encountered an error.
.IP "\fBcontents()\fR" 4
.IX Item "contents()"
Return the entire uncompressed member data or undef in scalar
context. When called in array context, returns \f(CW\*(C`( $string,
$status )\*(C'\fR; status will be \s-1AZ_OK\s0 on success:
.Sp
.Vb 4
\&    my $string = $member\->contents();
\&    # or
\&    my ( $string, $status ) = $member\->contents();
\&    die "error $status" unless $status == AZ_OK;
.Ve
.Sp
Can also be used to set the contents of a member (this may
change the class of the member):
.Sp
.Vb 1
\&    $member\->contents( "this is my new contents" );
.Ve
.ie n .IP "extractToFileHandle( $fh )" 4
.el .IP "extractToFileHandle( \f(CW$fh\fR )" 4
.IX Item "extractToFileHandle( $fh )"
.PD 0
.ie n .IP "extractToFileHandle( { fileHandle => $fh } )" 4
.el .IP "extractToFileHandle( { fileHandle => \f(CW$fh\fR } )" 4
.IX Item "extractToFileHandle( { fileHandle => $fh } )"
.PD
Extract (and uncompress, if necessary) the member's contents
to the given file handle. Return \s-1AZ_OK\s0 on success.
.Sp
For members representing symbolic links, pass the name of the
symbolic link as file handle. Ensure that all directories in the
path to the symbolic link already exist.
.SH "Archive::Zip::FileMember methods"
.IX Header "Archive::Zip::FileMember methods"
The Archive::Zip::FileMember class extends Archive::Zip::Member. It is the
base class for both ZipFileMember and NewFileMember classes. This class adds
an \f(CW\*(C`externalFileName\*(C'\fR and an \f(CW\*(C`fh\*(C'\fR member to keep track of the external
file.
.IP "\fBexternalFileName()\fR" 4
.IX Item "externalFileName()"
Return the member's external filename.
.IP "\fBfh()\fR" 4
.IX Item "fh()"
Return the member's read file handle. Automatically opens file if
necessary.
.SH "Archive::Zip::ZipFileMember methods"
.IX Header "Archive::Zip::ZipFileMember methods"
The Archive::Zip::ZipFileMember class represents members that have been read
from external zip files.
.IP "\fBdiskNumberStart()\fR" 4
.IX Item "diskNumberStart()"
Returns the disk number that the member's local header resides in.
Should be 0.
.IP "\fBlocalHeaderRelativeOffset()\fR" 4
.IX Item "localHeaderRelativeOffset()"
Returns the offset into the zip file where the member's local header
is.
.IP "\fBdataOffset()\fR" 4
.IX Item "dataOffset()"
Returns the offset from the beginning of the zip file to the member's
data.
.SH "REQUIRED MODULES"
.IX Header "REQUIRED MODULES"
Archive::Zip requires several other modules:
.PP
Carp
.PP
Compress::Raw::Zlib
.PP
Cwd
.PP
File::Basename
.PP
File::Copy
.PP
File::Find
.PP
File::Path
.PP
File::Spec
.PP
IO::File
.PP
IO::Seekable
.PP
Time::Local
.SH "BUGS AND CAVEATS"
.IX Header "BUGS AND CAVEATS"
.SS "When not to use Archive::Zip"
.IX Subsection "When not to use Archive::Zip"
If you are just going to be extracting zips (and/or other archives) you
are recommended to look at using Archive::Extract instead, as it is much
easier to use and factors out archive-specific functionality.
.SS "Zip64 Format Support"
.IX Subsection "Zip64 Format Support"
Since version 1.66 Archive::Zip supports the so-called zip64
format, which overcomes various limitations in the original zip
file format.  On some Perl interpreters, however, even version
1.66 and newer of Archive::Zip cannot support the zip64 format.
Among these are all Perl interpreters that lack 64\-bit support
and those older than version 5.10.0.
.PP
Constant \f(CW\*(C`ZIP64_SUPPORTED\*(C'\fR, exported with tag :CONSTANTS,
equals true if Archive::Zip on the current Perl interpreter
supports the zip64 format.  If it does not and you try to read or
write an archive in zip64 format, anyway, Archive::Zip returns an
error \f(CW\*(C`AZ_ERROR\*(C'\fR and reports an error message along the lines of
\&\*(L"zip64 format not supported on this Perl interpreter\*(R".
.ie n .SS """versionMadeBy"" and ""versionNeededToExtract"""
.el .SS "\f(CWversionMadeBy\fP and \f(CWversionNeededToExtract\fP"
.IX Subsection "versionMadeBy and versionNeededToExtract"
The zip64 format and the zip file format in general specify what
values to use for the \f(CW\*(C`versionMadeBy\*(C'\fR and
\&\f(CW\*(C`versionNeededToExtract\*(C'\fR fields in the local file header,
central directory file header, and zip64 \s-1EOCD\s0 record.  In
practice however, these fields seem to be more or less randomly
used by various archiver implementations.
.PP
To achieve a compromise between backward compatibility and
(whatever) standard compliance, Archive::Zip handles them as
follows:
.IP "\(bu" 4
For field \f(CW\*(C`versionMadeBy\*(C'\fR, Archive::Zip uses default value 20
(45 for the zip64 \s-1EOCD\s0 record) or any previously read value. It
never changes that value when writing a header, even if it is
written in zip64 format, or when writing the zip64 \s-1EOCD\s0 record.
.IP "\(bu" 4
Likewise for field \f(CW\*(C`versionNeededToExtract\*(C'\fR, but here
Archive::Zip forces a minimum value of 45 when writing a header
in zip64 format or the zip64 \s-1EOCD\s0 record.
.IP "\(bu" 4
Finally, Archive::Zip never depends on the values of these fields
in any way when reading an archive from a file or file handle.
.SS "Try to avoid IO::Scalar"
.IX Subsection "Try to avoid IO::Scalar"
One of the most common ways to use Archive::Zip is to generate Zip files
in-memory. Most people use IO::Scalar for this purpose.
.PP
Unfortunately, as of 1.11 this module no longer works with IO::Scalar
as it incorrectly implements seeking.
.PP
Anybody using IO::Scalar should consider porting to IO::String,
which is smaller, lighter, and is implemented to be perfectly compatible
with regular seekable filehandles.
.PP
Support for IO::Scalar most likely will \fBnot\fR be restored in the
future, as IO::Scalar itself cannot change the way it is implemented
due to back-compatibility issues.
.SS "Wrong password for encrypted members"
.IX Subsection "Wrong password for encrypted members"
When an encrypted member is read using the wrong password, you currently
have to re-read the entire archive to try again with the correct password.
.SH "TO DO"
.IX Header "TO DO"
* auto-choosing storing vs compression
.PP
* extra field hooks (see notes.txt)
.PP
* check for duplicates on addition/renaming?
.PP
* Text file extraction (line end translation)
.PP
* Reading zip files from non-seekable inputs
  (Perhaps by proxying through IO::String?)
.PP
* separate unused constants into separate module
.PP
* cookbook style docs
.PP
* Handle tainted paths correctly
.PP
* Work on better compatibility with other \s-1IO::\s0 modules
.PP
* Support encryption
.PP
* More user-friendly decryption
.SH "SUPPORT"
.IX Header "SUPPORT"
Bugs should be reported on GitHub
.PP
<https://github.com/redhotpenguin/perl\-Archive\-Zip/issues>
.PP
For other issues contact the maintainer.
.SH "AUTHOR"
.IX Header "AUTHOR"
Currently maintained by Fred Moyer <fred@redhotpenguin.com>
.PP
Previously maintained by Adam Kennedy <adamk@cpan.org>
.PP
Previously maintained by Steve Peters <steve@fisharerojo.org>.
.PP
File attributes code by Maurice Aubrey <maurice@lovelyfilth.com>.
.PP
Originally by Ned Konz <nedkonz@cpan.org>.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Some parts copyright 2006 \- 2012 Adam Kennedy.
.PP
Some parts copyright 2005 Steve Peters.
.PP
Original work copyright 2000 \- 2004 Ned Konz.
.PP
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Look at Archive::Zip::MemberRead which is a wrapper that allows one to
read Zip archive members as if they were files.
.PP
Compress::Raw::Zlib, Archive::Tar, Archive::Extract
