Archive-Zip
view release on metacpan or search on metacpan
lib/Archive/Zip.pm view on Meta::CPAN
=head1 MEMBER OPERATIONS
=head2 Member Class Methods
Several constructors allow you to construct members without 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.
=over 4
=item Archive::Zip::Member->newFromString( $stringOrStringRef [, $fileName ] )
=item Archive::Zip::Member->newFromString( { string => $stringOrStringRef
[, zipName => $fileName ] )
Construct a new member from the given string. Returns undef
on error.
my $member = Archive::Zip::Member->newFromString( 'This is a test' );
my $member = Archive::Zip::Member->newFromString( 'This is a test', 'test.txt' );
my $member = Archive::Zip::Member->newFromString( { string => 'This is a test', zipName => 'test.txt' } );
=item newFromFile( $fileName [, $zipName ] )
=item newFromFile( { filename => $fileName [, zipName => $zipName ] } )
Construct a new member from the given file. Returns undef on
error.
my $member = Archive::Zip::Member->newFromFile( 'xyz.txt' );
=item newDirectoryNamed( $directoryName [, $zipname ] )
=item newDirectoryNamed( { directoryName => $directoryName
[, zipName => $zipname ] } )
Construct a new member from the given directory.
C<$directoryName> must be a valid name on your file system; it does not
have to exist.
If given, C<$zipname> will be the name of the zip member; it must be a
valid Zip (Unix) name. If not given, it will be converted from
C<$directoryName>.
Returns undef on error.
my $member = Archive::Zip::Member->newDirectoryNamed( 'CVS/' );
=back
=head2 Member Simple Accessors
These methods get (and/or set) member attribute values.
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.
=over 4
=item zip64()
Returns whether the previous read or write of the member has been
done in zip64 format.
=item desiredZip64Mode()
Gets or sets whether the member's headers should be written in
zip64 format: As needed (ZIP64_AS_NEEDED), the default, or always
(ZIP64_HEADERS).
=item versionMadeBy()
Gets the field from the member header.
=item fileAttributeFormat( [ $format ] )
=item fileAttributeFormat( [ { format => $format ] } )
Gets or sets the field from the member header. These are
C<FA_*> values.
=item versionNeededToExtract()
Gets the field from the member header.
=item bitFlag()
Gets the general purpose bit field from the member header.
This is where the C<GPBF_*> bits live.
=item compressionMethod()
Returns the member compression method. This is the method
that is currently being used to compress the member data.
This will be COMPRESSION_STORED for added string or file
members, or any of the C<COMPRESSION_*> values for members
from a zip file. However, this module can only handle members
whose data is in COMPRESSION_STORED or COMPRESSION_DEFLATED
format.
=item desiredCompressionMethod( [ $method ] )
=item desiredCompressionMethod( [ { compressionMethod => $method } ] )
Get or set the member's C<desiredCompressionMethod>. This is
the compression method that will be used when the member is
written. Returns prior desiredCompressionMethod. Only
COMPRESSION_DEFLATED or COMPRESSION_STORED are valid
arguments. Changing to COMPRESSION_STORED will change the
member desiredCompressionLevel to 0; changing to
COMPRESSION_DEFLATED will change the member
desiredCompressionLevel to COMPRESSION_LEVEL_DEFAULT.
=item desiredCompressionLevel( [ $level ] )
lib/Archive/Zip.pm view on Meta::CPAN
=item internalFileAttributes()
Return the internal file attributes field from the zip
header. This is only set for members read from a zip file.
=item externalFileAttributes()
Return member attributes as read from the ZIP file. Note that
these are NOT UNIX!
=item unixFileAttributes( [ $newAttributes ] )
=item unixFileAttributes( [ { attributes => $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
comparisons.
=item localExtraField( [ $newField ] )
=item localExtraField( [ { field => $newField } ] )
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
AZ_FORMAT_ERROR, otherwise it returns AZ_OK.
=item cdExtraField( [ $newField ] )
=item cdExtraField( [ { field => $newField } ] )
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 AZ_FORMAT_ERROR, otherwise it returns AZ_OK.
=item extraFields()
Return both local and CD extra fields, concatenated.
=item fileComment( [ $newComment ] )
=item fileComment( [ { comment => $newComment } ] )
Get or set the member's file comment.
=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.
=item 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.
=item crc32String()
Return the CRC-32 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.
=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.
=item uncompressedSize()
Return the uncompressed size for this member.
=item password( [ $password ] )
Returns the password for this member to be used on decryption.
If $password is given, it will set the password for the decryption.
=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:
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
That shows that the password has to be set per member, and not per
archive. This might change in the future.
=item isTextFile( [ $flag ] )
=item isTextFile( [ { flag => $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.
=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
( run in 0.741 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )