archive::zip(3)
NAME
Archive::Zip - Provide an interface to ZIP archive files.
SYNOPSIS
use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); my $member = $zip->addDirectory( 'dirname/' ); $member = $zip->addString( 'This is a test', 'stringMember.txt' ); $member->desiredCompressionMethod( COMPRESSION_DEFLATED ); $member = $zip->addFile( 'xyz.pl', 'AnotherName.pl' ); die 'write error' unless $zip->writeToFileNamed( 'someZip.zip' ) == AZ_OK; $zip = Archive::Zip->new(); die 'read error' unless $zip->read( 'someZip.zip' ) == AZ_OK; $member = $zip->memberNamed( 'stringMember.txt' ); $member->desiredCompressionMethod( COMPRESSION_STORED ); die 'write error' unless $zip->writeToFileNamed( 'someOtherZip.zip' ) == AZ_OK;
DESCRIPTION
The Archive::Zip module allows a Perl program to create,
manipulate, read, and write Zip archive files.
Zip archives can be created, or you can read from existing
zip files. Once created, they can be written to files,
streams, or strings.
Members can be added, removed, extracted, replaced, rear
ranged, and enumerated. They can also be renamed or have
their dates, comments, or other attributes queried or mod
ified. Their data can be compressed or uncompressed as
needed. Members can be created from members in existing
Zip files, or from existing directories, files, or
strings.
This module uses the Compress::Zlib library to read and
write the compressed streams inside the files.
See Archive::Zip::Tree for easy operations on directories
full of files, or on entire Zip files. This is included in
the Archive::Zip distribution.
EXPORTS
- :CONSTANTS
- Exports the following constants:
- FA_MSDOS FA_UNIX GPBF_ENCRYPTED_MASK GPBF_DEFLAT
ING_COMPRESSION_MASK GPBF_HAS_DATA_DESCRIPTOR_MASK
COMPRESSION_STORED COMPRESSION_DEFLATED
IFA_TEXT_FILE_MASK IFA_TEXT_FILE IFA_BINARY_FILE COM
PRESSION_LEVEL_NONE COMPRESSION_LEVEL_DEFAULT COMPRES
SION_LEVEL_FASTEST COMPRESSION_LEVEL_BEST_COMPRESSION - :MISC_CONSTANTS
- Exports the following constants (only necessary for
extending the module): - FA_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_IMPLOD
ING_3_SHANNON_FANO_TREES_MASK GPBF_IS_COM
PRESSED_PATCHED_DATA_MASK COMPRESSION_SHRUNK DEFLAT
ING_COMPRESSION_NORMAL DEFLATING_COMPRESSION_MAXIMUM
DEFLATING_COMPRESSION_FAST DEFLATING_COMPRES
SION_SUPER_FAST COMPRESSION_REDUCED_1 COMPRES
SION_REDUCED_2 COMPRESSION_REDUCED_3 COMPRES
SION_REDUCED_4 COMPRESSION_IMPLODED COMPRESSION_TOK
ENIZED COMPRESSION_DEFLATED_ENHANCED COMPRES
SION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED - :ERROR_CODES
- Explained below. Returned from most methods.
- AZ_OK AZ_STREAM_END AZ_ERROR AZ_FORMAT_ERROR
AZ_IO_ERROR
OBJECT MODEL
- Inheritance
- Exporter
Archive::Zip Common baseclass, has defs.Archive::Zip::Archive A Zip archive.
Archive::Zip::Member Abstract superclass for all members.Archive::Zip::StringMember Member madefrom a string
Archive::Zip::FileMember Member madefrom an external fileArchive::Zip::ZipFileMember Member thatlives in a zip file
Archive::Zip::NewFileMember Member whosedata is in a fileArchive::Zip::DirectoryMember Member that isa directory
ERROR CODES
- Many of the methods in Archive::Zip return error codes.
These are implemented as inline subroutines, using the
"use constant" pragma. They can be imported into your
namespace using the ":CONSTANT" tag: - use Archive::Zip qw( :CONSTANTS );
...
die "whoops!" unless $zip->read( 'myfile.zip' ) == - AZ_OK;
- AZ_OK (0)
- Everything is fine.
- AZ_STREAM_END (1)
- The read stream (or central directory) ended normally.
- AZ_ERROR (2)
- There was some generic kind of error.
- AZ_FORMAT_ERROR (3)
- There is a format error in a ZIP file being read.
- AZ_IO_ERROR (4)
- There was an IO error.
COMPRESSION
Archive::Zip allows each member of a ZIP file to be com
pressed (using the Deflate algorithm) or uncompressed.
Other compression algorithms that some versions of ZIP
have been able to produce are not supported.
- Each member has two compression methods: the one it's
stored as (this is always COMPRESSION_STORED for string
and external file members), and the one you desire for the
member in the zip file. 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. You can
inquire about the current compression and set the desired
compression method: - my $member = $zip->memberNamed( 'xyz.txt' );
$member->compressionMethod(); # return current com - pression
# set to read uncompressed
$member->desiredCompressionMethod( COMPRESSION_STORED - );
# set to read compressed
$member->desiredCompressionMethod( COMPRESSION_DEFLAT - ED );
- There are two different compression methods:
- COMPRESSION_STORED
- file is stored (no compression)
- COMPRESSION_DEFLATED
- file is Deflated
- Compression Levels
- If a member's desiredCompressionMethod is COMPRES
SION_DEFLATED, you can choose different compression lev
els. This choice may affect the speed of compression and
decompression, as well as the size of the compressed mem
ber data.
$member->desiredCompressionLevel( 9 );- The levels given can be:
- 0 or COMPRESSION_LEVEL_NONE
- This is the same as saying
$member->desiredCompressionMethod( COMPRESSION_STORED ); - 1 .. 9
- 1 gives the best speed and worst compression, and 9
gives the best compression and worst speed. - COMPRESSION_LEVEL_FASTEST
- This is a synonym for level 1.
- COMPRESSION_LEVEL_BEST_COMPRESSION
- This is a synonym for level 9.
- COMPRESSION_LEVEL_DEFAULT
- This gives a good compromise between speed and com
pression, and is currently equivalent to 6 (this is in
the zlib code). - This is the level that will be used if not specified.
Archive::Zip methods
The Archive::Zip class (and its invisible subclass
Archive::Zip::Archive) implement generic zip file func
tionality.
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.
Constructor
- new( [$fileName] )
- Make a new, empty zip archive.
my $zip = Archive::Zip->new(); - If an additional argument is passed, new() will call
read() to read the contents of an archive:
my $zip = Archive::Zip->new( 'xyz.zip' ); - If a filename argument is passed and the read fails
for any reason, new will return undef. For this rea
son, it may be better to call read separately. - Zip Archive Utility Methods
- These Archive::Zip methods may be called as functions or
as object methods. Do not call them as class methods:
$zip = Archive::Zip->new();
$crc = Archive::Zip::computeCRC32( 'ghijkl' ); # OK
$crc = $zip->computeCRC32( 'ghijkl' ); #- also OK
- $crc = Archive::Zip->computeCRC32( 'ghijkl' ); #
- NOT OK
- Archive::Zip::computeCRC32( $string [, $crc] )
- This is a utility function that uses the Com
press::Zlib CRC routine to compute a CRC-32. - You can get the CRC of a string:
$crc = Archive::Zip::computeCRC32( $string ); - Or you can compute the running CRC:
$crc = 0;
$crc = Archive::Zip::computeCRC32( 'abcdef', $crc);
$crc = Archive::Zip::computeCRC32( 'ghijkl', $crc); - Archive::Zip::setChunkSize( $number )
- Change chunk size used for reading and writing. Cur
rently, this defaults to 32K. This is not exportable,
so you must call it like:
Archive::Zip::setChunkSize( 4096 ); - or as a method on a zip (though this is a global set
ting). Returns old chunk size. - Archive::Zip::setErrorHandler( subroutine )
- Change the subroutine called with error strings. This
defaults to Carp::carp, but you may want to change
it to get the error strings. - This is not exportable, so you must call it like:
Archive::Zip::setErrorHandler( myErrorHandler ); - If no error handler is passed, 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):
$Carp::CarpLevel++; - Zip Archive Accessors
- members()
- Return a copy of my members array
my @members = $zip->members(); - numberOfMembers()
- Return the number of members I have
- memberNames()
- Return a list of the (internal) file names of my mem
bers - memberNamed( $string )
- Return ref to member whose filename equals given file
name or undef - membersMatching( $regex )
- Return array of members whose filenames match given
regular expression in list context. Returns number of
matching members in scalar context.
my @textFileMembers = $zip->membersMatching('.*.txt' );
# or
my $numberOfTextFiles = $zip->membersMatching('.*.txt' ); - diskNumber()
- Return the disk that I start on. Not used for writing
zips, but might be interesting if you read a zip in.
This had better be 0, as Archive::Zip does not handle
multi-volume archives. - 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 had
better be 0, as Archive::Zip does not handle multivolume archives. - numberOfCentralDirectoriesOnThisDisk()
- Return the number of CD structures on this disk. Not
used for writing zips, but might be interesting if you
read a zip in. - numberOfCentralDirectories()
- Return the number of CD structures in the whole zip.
Not used for writing zips, but might be interesting if
you read a zip in. - centralDirectorySize()
- Returns central directory size, as read from an exter
nal zip file. Not used for writing zips, but might be
interesting if you read a zip in. - centralDirectoryOffsetWRTStartingDiskNumber()
- Returns the offset into the zip file where the CD
begins. Not used for writing zips, but might be
interesting if you read a zip in. - zipfileComment( [$string] )
- Get or set the zipfile comment. Returns the old com
ment.
print $zip->zipfileComment();
$zip->zipfileComment( 'New Comment' ); - eocdOffset()
- Returns the (unexpected) number of bytes between where
the EOCD 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
EOCD. Not used for writing zips, but might be inter
esting if you read a zip in. - Here is an example of how you can diagnose this:
my $zip = Archive::Zip->new('somefile.zip');
if ($zip->eocdOffset())
{warn "A virus has added ", $zip->eocdOffset, "bytes of garbage0;} - 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 ref
erence 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). - removeMember( $memberOrName )
Remove and return the given member, or match its name
and remove it. Returns undef if member name doesn't
exist in this Zip. No-op if member does not belong to
this zip. - replaceMember( $memberOrName, $newMember )
Remove and return the given member, or match its name
and remove it. Replace with new member. Returns
undef if member name doesn't exist in this Zip.
my $member1 = $zip->removeMember( 'xyz' );
my $member2 = $zip->replaceMember( 'abc', $member1);
# now, $member2 (named 'abc') is not in $zip,
# and $member1 (named 'xyz') is, having taken$member2's place. - extractMember( $memberOrName [, $extractedName ] )
- Extract the given member, or match its name and
extract it. Returns undef if member doesn't 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. - All necessary directories will be created.
- Returns "AZ_OK" on success.
- extractMemberWithoutPaths( $memberOrName [, $extractedName
] ) - 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
doesn't 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 "AZ_OK" on success.
- addMember( $member )
- Append a member (possibly from another zip file) to
the zip file. Returns the new member. Generally, you
will use addFile(), addDirectory(), addString(), or read() to add members.
# Move member named 'abc' to end of zip:
my $member = $zip->removeMember( 'abc' );
$zip->addMember( $member ); - addFile( $fileName [, $newName ] )
- 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 COMPRES
SION_DEFLATED. The file attributes and last modifica
tion 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. - The text mode bit will be set if the contents appears
to be text (as returned by the "-T" perl operator). - The optional second argument sets the internal file
name to something different than the given $fileName. - addString( $stringOrStringRef [, $name] )
- Append a member created from the given string or
string reference. The name is given by the optional
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.
my $member = $zip->addString( 'This is a test','test.txt' ); - addDirectory( $directoryName [, $fileName ] )
- 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. The optional second
argument sets the name of the archive member (which
defaults to $directoryName) - Returns the new member.
- contents( $memberOrMemberName [, $newContents ] )
- Returns the uncompressed data for a particular member,
or undef.
print "xyz.txt contains " . $zip->contents('xyz.txt' ); - Also can change the contents of a member:
$zip->contents( 'xyz.txt', 'This is the new contents' ); - Zip Archive I/O operations
- A Zip archive can be written to a file or file handle, or
read from one. - writeToFileNamed( $fileName )
- Write a zip archive to named file. Returns "AZ_OK" on
success. - Note that if you use the same name as an existing zip
file that you read in, you will clobber ZipFileMem
bers. So instead, write to a different file name,
then delete the original.
my $status = $zip->writeToFileNamed( 'xx.zip' );
die "error somewhere" if $status != AZ_OK; - Here's an example of writing back to the original
file, when the original file may or may not exist.
Note the construction of a tempfile in the same direc
tory so that "rename" will work:
use Archive::Zip;
use File::Temp;
use File::Basename;my $target = 'somefile.zip';
my $zip = Archive::Zip->new();
$zip->read($target) && die "can't read $target0if -f $target;#
# now add/delete/rename members, etc.
#
if (-f $target) # existing file?
{my ($tmpfh, $tmpname) = File::Temp::tempfile(DIR => dirname($target));
$zip->writeToFileHandle( $tmpfh ) && die "Can'twrite to $tmpname0;
$tmpfh->close();
unlink($target) or die "can't remove $target:$!0;
rename($tmpname, $target) or die "can't rename$target: $!0;}
else
{$zip->writeToFileNamed($target) && die "can'twrite to $target0;} - writeToFileHandle( $fileHandle [, $seekable] )
- Write a zip archive to a file handle. Return AZ_OK 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" test returns true. This
could fail on some operating systems, though.
my $fh = IO::File->new( 'someFile.zip', 'w' );
if ( $zip->writeToFileHandle( $fh ) != AZ_OK){# error handling} - 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:
my $fh = IO::File->new( '| cat > somefile.zip',- 'w' );
$zip->writeToFileHandle( $fh, 0 ); # fh is not - seekable
- If this method fails during the write of a member,
that member and all following it will return false
from "wasWritten()". See writeCentralDirectory() for a way to deal with this. - writeCentralDirectory( $fileHandle [, $offset ] )
- Writes the central directory structure to the given
file handle. Returns AZ_OK on success. - If given an $offset, will seek to that point before
writing. - This can be used for recovery in cases where
writeToFileHandle or writeToFileNamed returns an IO
error because of running out of space on the destina
tion file. - You can truncate the zip by seeking backwards and then
writing the directory:
my $fh = IO::File->new( 'someFile.zip', 'w' );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());}} - read( $fileName )
- Read zipfile headers from a zip file, appending new
members. Returns "AZ_OK" or error code.
my $zipFile = Archive::Zip->new();
my $status = $zipFile->read( '/some/FileName.zip'); - readFromFileHandle( $fileHandle, $filename )
- Read zipfile headers from an already-opened file han
dle, appending new members. Does not close the file
handle. Returns "AZ_OK" or error code.
my $fh = IO::File->new( '/some/FileName.zip', 'r');
my $zip1 = Archive::Zip->new();
my $status = $zip1->readFromFileHandle( $fh );
my $zip2 = Archive::Zip->new();
$status = $zip2->readFromFileHandle( $fh );
MEMBER OPERATIONS
Member Class Methods
Several constructors allow you to construct members with
out adding them to a zip archive.
These work the same as the addFile(), addDirectory(), and
addString() zip instance methods described above, but they
don't add the new members to a zip.
- Archive::Zip::Member->newFromString( $stringOrStringRef [,
$fileName] ) - Construct a new member from the given string. Returns
undef on error.
my $member = Archive::Zip::Member->newFromString('This is a test','xyz.txt'); - newFromFile( $fileName )
- Construct a new member from the given file. Returns
undef on error.
my $member = Archive::Zip::Member->newFromFile('xyz.txt' ); - newDirectoryNamed( $directoryName )
- Construct a new member from the given directory.
Returns undef on error.
my $member = Archive::Zip::Member->newDirectoryNamed( 'CVS/' ); - Member Simple accessors
- These methods get (and/or set) member attribute values.
- versionMadeBy()
- Gets the field from my member header.
- fileAttributeFormat( [$format] )
- Gets or sets the field from the member header. These
are "FA_*" values. - versionNeededToExtract()
- Gets the field from my member header.
- bitFlag()
- Gets the general purpose bit field from my member
header. This is where the "GPBF_*" bits live. - compressionMethod()
- Returns my compression method. This is the method that
is currently being used to compress my data. - This will be COMPRESSION_STORED for added string or
file members, or any of the "COMPRESSION_*" values for
members from a zip file. However, this module can
only handle members whose data is in COMPRES
SION_STORED or COMPRESSION_DEFLATED format. - desiredCompressionMethod( [$method] )
- Get or set my desiredCompressionMethod This is the
method that will be used to write. Returns prior
desiredCompressionMethod. - Only COMPRESSION_DEFLATED or COMPRESSION_STORED are
valid arguments. - Changing to COMPRESSION_STORED will change my desired
CompressionLevel to 0; changing to COMPRES
SION_DEFLATED will change my desiredCompressionLevel
to COMPRESSION_LEVEL_DEFAULT. - desiredCompressionLevel( [$method] )
- Get or set my desiredCompressionLevel This is the
method that will be used to write. Returns prior
desiredCompressionLevel. - Valid arguments are 0 through 9, COMPRES
SION_LEVEL_NONE, COMPRESSION_LEVEL_DEFAULT,
COMPRESSION_LEVEL_BEST_COMPRESSION, and COMPRES
SION_LEVEL_FASTEST. - 0 or COMPRESSION_LEVEL_NONE will change the desired
CompressionMethod to COMPRESSION_STORED. All other
arguments will change the desiredCompressionMethod to
COMPRESSION_DEFLATED. - fileName()
- Get or set my internal filename. Returns the (possi
bly new) filename. - Names will have backslashes converted to forward
slashes, and will have multiple consecutive slashes
converted to single ones. - lastModFileDateTime()
- Return my last modification date/time stamp in MS-DOS
format. - lastModTime()
- Return my last modification date/time stamp, converted
to unix localtime format.
print "Mod Time: " . scalar( localtime( $member->lastModTime() ) ); - setLastModFileDateTimeFromUnix()
- Set my lastModFileDateTime from the given unix time.
$member->setLastModFileDateTimeFromUnix( time() ); - internalFileAttributes()
- Return the internal file attributes field from the zip
header. This is only set for members read from a zip
file. - externalFileAttributes()
- Return member attributes as read from the ZIP file.
Note that these are NOT UNIX! - unixFileAttributes( [$newAttributes] )
- Get or set the member's file attributes using UNIX
file attributes. Returns old attributes.
my $oldAttribs = $member->unixFileAttributes( 0666); - Note that the return value has more than just the file
permissions, so you will have to mask off the lowest
bits for comparisions. - localExtraField( [$newField] )
- Gets or sets the extra field that was read from the
local header. This is not set for a member from a zip
file until after the member has been written out. - The extra field must be in the proper format.
- cdExtraField( [$newField] )
- Gets or sets the extra field that was read from the
central directory header. - The extra field must be in the proper format.
- extraFields()
- Return both local and CD extra fields, concatenated.
- fileComment( [$newComment] )
- Get or set the member's file comment.
- 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.
- crc32()
- Return the CRC-32 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. - crc32String()
- Return the CRC-32 value for this member as an 8 char
acter 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. - 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. - uncompressedSize()
- Return the uncompressed size for this member.
- isEncrypted()
- Return true if this member is encrypted. The
Archive::Zip module does not currently create or
extract encrypted members. - isTextFile( [$flag] )
- 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. - 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. - extractToFileNamed( $fileName )
- Extract me to a file with the given name. The file
will be created with default modes. Directories will
be created as needed. - Returns AZ_OK on success.
- isDirectory()
- Returns true if I am a directory.
- writeLocalHeaderRelativeOffset()
- Returns the file offset in bytes the last time I was
written. - wasWritten()
- Returns true if I was successfully written. Reset at
the beginning of a write attempt. - Low-level member data reading
- It is possible to use lower-level routines to access mem
ber data streams, rather than the extract* methods and
contents(). - For instance, here is how to print the uncompressed con
tents of a member in chunks using these methods:
my ( $member, $status, $bufferRef );
$member = $zip->memberNamed( 'xyz.txt' );
$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(); - readChunk( [$chunkSize] )
- This reads the next chunk of given size from the mem
ber'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
AZ_OK on success until the last chunk, where it
returns AZ_STREAM_END. Returns "( ytes, $status)".
my ( $outRef, $status ) = $self->readChunk();
print $$outRef if $status != AZ_OK && $status !=AZ_STREAM_END; - rewindData()
- Rewind data and set up for reading data streams or
writing zip files. Can take options for
"inflateInit()" or "deflateInit()", but this isn't
likely to be necessary. Subclass overrides should
call this method. Returns "AZ_OK" on success. - endRead()
- Reset the read variables and free the inflater or
deflater. Must be called to close files, etc. - Returns AZ_OK on success.
- readIsDone()
- Return true if the read has run out of data or errored
out. - contents()
- Return the entire uncompressed member data or undef in
scalar context. When called in array context, returns
"( $string, $status )"; status will be AZ_OK on suc
cess:
my $string = $member->contents();
# or
my ( $string, $status ) = $member->contents();
die "error $status" unless $status == AZ_OK; - Can also be used to set the contents of a member (this
may change the class of the member):
$member->contents( "this is my new contents" ); - extractToFileHandle( $fh )
- Extract (and uncompress, if necessary) my contents to
the given file handle. Return AZ_OK on success.
Archive::Zip::FileMember methods
The Archive::Zip::FileMember class extends
Archive::Zip::Member. It is the base class for both Zip
FileMember and NewFileMember classes. This class adds an
"externalFileName" and an "fh" member to keep track of the
external file.
- externalFileName()
- Return my external filename.
- fh()
- Return my read file handle. Automatically opens file
if necessary.
Archive::Zip::ZipFileMember methods
The Archive::Zip::ZipFileMember class represents members
that have been read from external zip files.
- diskNumberStart()
- Returns the disk number that my local header resides
in. Had better be 0. - localHeaderRelativeOffset()
- Returns the offset into the zip file where my local
header is. - dataOffset()
- Returns the offset from the beginning of the zip file
to my data.
AUTHOR
Ned Konz, nedkonz@cpan.org
COPYRIGHT
Copyright (c) 2000-2002 Ned Konz. All rights reserved.
This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.
SEE ALSO
Compress::Zlib Archive::Tar
- There is a Japanese translation of this document at
http://www.necoware.com/~deq/perl/doc-ja/Archive-Zip.html
that was done by DEQ <deq@oct.zaq.ne.jp> . Thanks!