releasing/cbrtools/perl/Archive/Zip.pm
author lorewang
Wed, 17 Nov 2010 11:24:29 +0800
changeset 685 39f7ecf8fbc7
parent 602 3145852acc89
permissions -rw-r--r--
pull from trunk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#! perl -w
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# $Revision: 1.39 $
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# Copyright (c) 2000 Ned Konz. All rights reserved.  This program is free
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# software; you can redistribute it and/or modify it under the same terms
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
Archive::Zip - Provide an interface to ZIP archive files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
 my $zip = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
 my $member = $zip->addDirectory( 'dirname/' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
 $member = $zip->addString( 'This is a test', 'stringMember.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
 $member->desiredCompressionMethod( COMPRESSION_DEFLATED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
 $member = $zip->addFile( 'xyz.pl', 'AnotherName.pl' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
 die 'write error' if $zip->writeToFileNamed( 'someZip.zip' ) != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
 $zip = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
 die 'read error' if $zip->read( 'someZip.zip' ) != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
 $member = $zip->memberNamed( 'stringMember.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
 $member->desiredCompressionMethod( COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
 die 'write error' if $zip->writeToFileNamed( 'someOtherZip.zip' ) != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
The Archive::Zip module allows a Perl program to create,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
manipulate, read, and write Zip archive files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
Zip archives can be created, or you can read from existing zip files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
Once created, they can be written to files, streams, or strings.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
Members can be added, removed, extracted, replaced, rearranged,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
and enumerated.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
They can also be renamed or have their dates, comments,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
or other attributes queried or modified.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
Their data can be compressed or uncompressed as needed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
Members can be created from members in existing Zip files,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
or from existing directories, files, or strings.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
This module uses the L<Compress::Zlib|Compress::Zlib> library
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
to read and write the compressed streams inside the files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
=head1 EXPORTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
=item :CONSTANTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
Exports the following constants:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
FA_MSDOS FA_UNIX GPBF_ENCRYPTED_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
GPBF_DEFLATING_COMPRESSION_MASK GPBF_HAS_DATA_DESCRIPTOR_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
COMPRESSION_STORED COMPRESSION_DEFLATED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
IFA_TEXT_FILE_MASK IFA_TEXT_FILE IFA_BINARY_FILE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
COMPRESSION_LEVEL_NONE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
COMPRESSION_LEVEL_DEFAULT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
COMPRESSION_LEVEL_FASTEST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
COMPRESSION_LEVEL_BEST_COMPRESSION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
=item :MISC_CONSTANTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
Exports the following constants (only necessary for extending the module):
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
FA_AMIGA FA_VAX_VMS FA_VM_CMS FA_ATARI_ST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
FA_OS2_HPFS FA_MACINTOSH FA_Z_SYSTEM FA_CPM FA_WINDOWS_NTFS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
GPBF_IS_COMPRESSED_PATCHED_DATA_MASK COMPRESSION_SHRUNK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
DEFLATING_COMPRESSION_NORMAL DEFLATING_COMPRESSION_MAXIMUM
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
DEFLATING_COMPRESSION_FAST DEFLATING_COMPRESSION_SUPER_FAST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
COMPRESSION_REDUCED_1 COMPRESSION_REDUCED_2 COMPRESSION_REDUCED_3
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
COMPRESSION_REDUCED_4 COMPRESSION_IMPLODED COMPRESSION_TOKENIZED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
COMPRESSION_DEFLATED_ENHANCED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
=item :ERROR_CODES
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
Explained below. Returned from most methods.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
AZ_OK AZ_STREAM_END AZ_ERROR AZ_FORMAT_ERROR AZ_IO_ERROR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
=head1 OBJECT MODEL
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
=head2 Inheritance
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
 Exporter
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
    Archive::Zip                            Common base class, has defs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
        Archive::Zip::Archive               A Zip archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
        Archive::Zip::Member                Abstract superclass for all members.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
            Archive::Zip::StringMember      Member made from a string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
            Archive::Zip::FileMember        Member made from an external file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
                Archive::Zip::ZipFileMember Member that lives in a zip file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
                Archive::Zip::NewFileMember Member whose data is in a file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
            Archive::Zip::DirectoryMember   Member that is a directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
# class Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
# Note that the package Archive::Zip exists only for exporting and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
# sharing constants. Everything else is in another package
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
# in this file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
# Creation of a new Archive::Zip object actually creates a new object
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
# of class Archive::Zip::Archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
package Archive::Zip;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
require 5.003_96;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
use Carp ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
use IO::File ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
use IO::Seekable ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
use Compress::Zlib ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
use POSIX qw(_exit);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
use vars qw( @ISA @EXPORT_OK %EXPORT_TAGS $VERSION $ChunkSize $ErrorHandler );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
if ($Compress::Zlib::VERSION < 1.06)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
    if ($] < 5.006001)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
       print STDERR "Your current perl libraries are too old; please upgrade to Perl 5.6.1\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
    else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
       print STDERR "There is a problem with your perl run time environment.\n An old version of Zlib is in use,\n please check your perl installation (5.6.1 or later) and your perl libraries\n"; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
    STDERR->flush;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
    POSIX:_exit(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
# This is the size we'll try to read, write, and (de)compress.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
# You could set it to something different if you had lots of memory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
# and needed more speed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
$ChunkSize = 32768;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
$ErrorHandler = \&Carp::carp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
# BEGIN block is necessary here so that other modules can use the constants.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
BEGIN
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
	require Exporter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
	$VERSION = "0.11";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
	@ISA = qw( Exporter );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
	my @ConstantNames = qw( FA_MSDOS FA_UNIX GPBF_ENCRYPTED_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
	GPBF_DEFLATING_COMPRESSION_MASK GPBF_HAS_DATA_DESCRIPTOR_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
	COMPRESSION_STORED COMPRESSION_DEFLATED COMPRESSION_LEVEL_NONE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
	COMPRESSION_LEVEL_DEFAULT COMPRESSION_LEVEL_FASTEST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
	COMPRESSION_LEVEL_BEST_COMPRESSION IFA_TEXT_FILE_MASK IFA_TEXT_FILE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
	IFA_BINARY_FILE );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
	my @MiscConstantNames = qw( FA_AMIGA FA_VAX_VMS FA_VM_CMS FA_ATARI_ST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
	FA_OS2_HPFS FA_MACINTOSH FA_Z_SYSTEM FA_CPM FA_WINDOWS_NTFS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
	GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
	GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
	GPBF_IS_COMPRESSED_PATCHED_DATA_MASK COMPRESSION_SHRUNK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
	DEFLATING_COMPRESSION_NORMAL DEFLATING_COMPRESSION_MAXIMUM
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
	DEFLATING_COMPRESSION_FAST DEFLATING_COMPRESSION_SUPER_FAST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
	COMPRESSION_REDUCED_1 COMPRESSION_REDUCED_2 COMPRESSION_REDUCED_3
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
	COMPRESSION_REDUCED_4 COMPRESSION_IMPLODED COMPRESSION_TOKENIZED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
	COMPRESSION_DEFLATED_ENHANCED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
	COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
	my @ErrorCodeNames = qw( AZ_OK AZ_STREAM_END AZ_ERROR AZ_FORMAT_ERROR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
	AZ_IO_ERROR );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
	my @PKZipConstantNames = qw( SIGNATURE_FORMAT SIGNATURE_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
	LOCAL_FILE_HEADER_SIGNATURE LOCAL_FILE_HEADER_FORMAT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
	LOCAL_FILE_HEADER_LENGTH DATA_DESCRIPTOR_FORMAT DATA_DESCRIPTOR_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
	CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
	CENTRAL_DIRECTORY_FILE_HEADER_FORMAT CENTRAL_DIRECTORY_FILE_HEADER_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
	END_OF_CENTRAL_DIRECTORY_SIGNATURE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
	END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING END_OF_CENTRAL_DIRECTORY_FORMAT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
	END_OF_CENTRAL_DIRECTORY_LENGTH );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
	my @UtilityMethodNames = qw( _error _ioError _formatError
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
		_subclassResponsibility _binmode _isSeekable _newFileHandle);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
	@EXPORT_OK = ( 'computeCRC32' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
	%EXPORT_TAGS = ( 'CONSTANTS' => \@ConstantNames,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
			'MISC_CONSTANTS' => \@MiscConstantNames,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
			'ERROR_CODES' => \@ErrorCodeNames,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
			# The following two sets are for internal use only
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
			'PKZIP_CONSTANTS' => \@PKZipConstantNames,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
			'UTILITY_METHODS' => \@UtilityMethodNames );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
	# Add all the constant names and error code names to @EXPORT_OK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
	Exporter::export_ok_tags( 'CONSTANTS', 'ERROR_CODES',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
		'PKZIP_CONSTANTS', 'UTILITY_METHODS', 'MISC_CONSTANTS' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
# ------------------------- begin exportable error codes -------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
=head1 ERROR CODES
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
Many of the methods in Archive::Zip return error codes.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
These are implemented as inline subroutines, using the C<use constant> pragma.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
They can be imported into your namespace using the C<:CONSTANT>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
tag:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
    use Archive::Zip qw( :CONSTANTS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
    ...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
    die "whoops!" if $zip->read( 'myfile.zip' ) != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
=item AZ_OK (0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
Everything is fine.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
=item AZ_STREAM_END (1)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
The read stream (or central directory) ended normally.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
=item AZ_ERROR (2)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
There was some generic kind of error.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
=item AZ_FORMAT_ERROR (3)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
There is a format error in a ZIP file being read.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
=item AZ_IO_ERROR (4)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
There was an IO error.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
use constant AZ_OK			=> 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
use constant AZ_STREAM_END	=> 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
use constant AZ_ERROR		=> 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
use constant AZ_FORMAT_ERROR => 3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
use constant AZ_IO_ERROR	=> 4;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
# ------------------------- end exportable error codes ---------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
# ------------------------- begin exportable constants ---------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
# File types
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
# Values of Archive::Zip::Member->fileAttributeFormat()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
use constant FA_MSDOS		=> 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
use constant FA_UNIX		=> 3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
# general-purpose bit flag masks
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
# Found in Archive::Zip::Member->bitFlag()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
use constant GPBF_ENCRYPTED_MASK						=> 1 << 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
use constant GPBF_DEFLATING_COMPRESSION_MASK			=> 3 << 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
use constant GPBF_HAS_DATA_DESCRIPTOR_MASK				=> 1 << 3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
# deflating compression types, if compressionMethod == COMPRESSION_DEFLATED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
# ( Archive::Zip::Member->bitFlag() & GPBF_DEFLATING_COMPRESSION_MASK )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
use constant DEFLATING_COMPRESSION_NORMAL		=> 0 << 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
use constant DEFLATING_COMPRESSION_MAXIMUM		=> 1 << 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
use constant DEFLATING_COMPRESSION_FAST			=> 2 << 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
use constant DEFLATING_COMPRESSION_SUPER_FAST	=> 3 << 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
# compression method
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
=head1 COMPRESSION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
Archive::Zip allows each member of a ZIP file to be compressed (using
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
the Deflate algorithm) or uncompressed. Other compression algorithms
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
that some versions of ZIP have been able to produce are not supported.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
Each member has two compression methods: the one it's stored as (this
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
is always COMPRESSION_STORED for string and external file members),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
and the one you desire for the member in the zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
These can be different, of course, so you can make a zip member that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
is not compressed out of one that is, and vice versa.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
You can inquire about the current compression and set
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
the desired compression method:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
    my $member = $zip->memberNamed( 'xyz.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
    $member->compressionMethod();    # return current compression
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
    # set to read uncompressed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
    $member->desiredCompressionMethod( COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
    # set to read compressed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
    $member->desiredCompressionMethod( COMPRESSION_DEFLATED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
There are two different compression methods:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
=item COMPRESSION_STORED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
file is stored (no compression)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
=item COMPRESSION_DEFLATED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
file is Deflated
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
=head2 Compression Levels
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
If a member's desiredCompressionMethod is COMPRESSION_DEFLATED,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
you can choose different compression levels. This choice may
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
affect the speed of compression and decompression, as well as
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
the size of the compressed member data.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
    $member->desiredCompressionLevel( 9 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
The levels given can be:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
=item 0 or COMPRESSION_LEVEL_NONE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
This is the same as saying
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
    $member->desiredCompressionMethod( COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
=item 1 .. 9
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
1 gives the best speed and worst compression, and 9 gives the best
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
compression and worst speed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
=item COMPRESSION_LEVEL_FASTEST
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
This is a synonym for level 1.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
=item COMPRESSION_LEVEL_BEST_COMPRESSION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
This is a synonym for level 9.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
=item COMPRESSION_LEVEL_DEFAULT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
This gives a good compromise between speed and compression, and is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
currently equivalent to 6 (this is in the zlib code).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
This is the level that will be used if not specified.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
# these two are the only ones supported in this module
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
use constant COMPRESSION_STORED => 0;	# file is stored (no compression)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
use constant COMPRESSION_DEFLATED => 8;	# file is Deflated
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
use constant COMPRESSION_LEVEL_NONE => 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
use constant COMPRESSION_LEVEL_DEFAULT => -1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
use constant COMPRESSION_LEVEL_FASTEST => 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
use constant COMPRESSION_LEVEL_BEST_COMPRESSION => 9;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
# internal file attribute bits
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
# Found in Archive::Zip::Member::internalFileAttributes()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
use constant IFA_TEXT_FILE_MASK	=> 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
use constant IFA_TEXT_FILE		=> 1;	# file is apparently text
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
use constant IFA_BINARY_FILE	=> 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
# PKZIP file format miscellaneous constants (for internal use only)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
use constant SIGNATURE_FORMAT => "V";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
use constant SIGNATURE_LENGTH => 4;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
use constant LOCAL_FILE_HEADER_SIGNATURE	=> 0x04034b50;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
use constant LOCAL_FILE_HEADER_FORMAT		=> "v3 V4 v2";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
use constant LOCAL_FILE_HEADER_LENGTH		=> 26;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
use constant DATA_DESCRIPTOR_FORMAT	=> "V3";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
use constant DATA_DESCRIPTOR_LENGTH	=> 12;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
use constant CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE => 0x02014b50;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
use constant CENTRAL_DIRECTORY_FILE_HEADER_FORMAT => "C2 v3 V4 v5 V2";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
use constant CENTRAL_DIRECTORY_FILE_HEADER_LENGTH => 42;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
use constant END_OF_CENTRAL_DIRECTORY_SIGNATURE => 0x06054b50;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
use constant END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING => pack( "V",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
	END_OF_CENTRAL_DIRECTORY_SIGNATURE );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
use constant END_OF_CENTRAL_DIRECTORY_FORMAT => "v4 V2 v";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
use constant END_OF_CENTRAL_DIRECTORY_LENGTH => 18;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
use constant FA_AMIGA		=> 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
use constant FA_VAX_VMS		=> 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
use constant FA_VM_CMS		=> 4;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
use constant FA_ATARI_ST	=> 5;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
use constant FA_OS2_HPFS	=> 6;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
use constant FA_MACINTOSH	=> 7;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
use constant FA_Z_SYSTEM	=> 8;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
use constant FA_CPM			=> 9;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
use constant FA_WINDOWS_NTFS => 10;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
use constant GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK	=> 1 << 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
use constant GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK	=> 1 << 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
use constant GPBF_IS_COMPRESSED_PATCHED_DATA_MASK		=> 1 << 5;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
# the rest of these are not supported in this module
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
use constant COMPRESSION_SHRUNK => 1;	# file is Shrunk
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
use constant COMPRESSION_REDUCED_1 => 2;# file is Reduced CF=1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
use constant COMPRESSION_REDUCED_2 => 3;# file is Reduced CF=2
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
use constant COMPRESSION_REDUCED_3 => 4;# file is Reduced CF=3
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
use constant COMPRESSION_REDUCED_4 => 5;# file is Reduced CF=4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
use constant COMPRESSION_IMPLODED => 6;	# file is Imploded
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
use constant COMPRESSION_TOKENIZED => 7;# reserved for Tokenizing compr.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
use constant COMPRESSION_DEFLATED_ENHANCED => 9; # reserved for enh. Deflating
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
use constant COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED => 10;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
# ------------------------- end of exportable constants ---------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
=head1  Archive::Zip methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
The Archive::Zip class (and its invisible subclass Archive::Zip::Archive)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
implement generic zip file functionality.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
Creating a new Archive::Zip object actually makes an Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
object, but you don't have to worry about this unless you're subclassing.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
=head2 Constructor
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
use constant ZIPARCHIVECLASS 	=> 'Archive::Zip::Archive';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
use constant ZIPMEMBERCLASS		=> 'Archive::Zip::Member';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
=item new( [$fileName] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
Make a new, empty zip archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
    my $zip = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
If an additional argument is passed, new() will call read() to read the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
contents of an archive:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
    my $zip = Archive::Zip->new( 'xyz.zip' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
If a filename argument is passed and the read fails for any reason, new
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
will return undef. For this reason, it may be better to call read
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
separately.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
sub new	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
	return $class->ZIPARCHIVECLASS->new( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
=head2  Utility Methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
These Archive::Zip methods may be called as functions or as object
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
methods. Do not call them as class methods:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
    $zip = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
    $crc = Archive::Zip::computeCRC32( 'ghijkl' );    # OK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
    $crc = $zip->computeCRC32( 'ghijkl' );            # also OK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
    $crc = Archive::Zip->computeCRC32( 'ghijkl' );    # NOT OK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
=item Archive::Zip::computeCRC32( $string [, $crc] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
This is a utility function that uses the Compress::Zlib CRC
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
routine to compute a CRC-32.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
You can get the CRC of a string:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
    $crc = Archive::Zip::computeCRC32( $string );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
Or you can compute the running CRC:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
    $crc = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
    $crc = Archive::Zip::computeCRC32( 'abcdef', $crc );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
    $crc = Archive::Zip::computeCRC32( 'ghijkl', $crc );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
sub computeCRC32	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
	my $data = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
	$data = shift if ref( $data );	# allow calling as an obj method
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
	my $crc = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
	return Compress::Zlib::crc32( $data, $crc );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
=item Archive::Zip::setChunkSize( $number )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
Change chunk size used for reading and writing.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
Currently, this defaults to 32K.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
This is not exportable, so you must call it like:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
    Archive::Zip::setChunkSize( 4096 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
or as a method on a zip (though this is a global setting).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
Returns old chunk size.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
sub setChunkSize	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
	my $chunkSize = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
	$chunkSize = shift if ref( $chunkSize );	# object method on zip?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
	my $oldChunkSize = $Archive::Zip::ChunkSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
	$Archive::Zip::ChunkSize = $chunkSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
	return $oldChunkSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
=item Archive::Zip::setErrorHandler( \&subroutine )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
Change the subroutine called with error strings.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
This defaults to \&Carp::carp, but you may want to change
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
it to get the error strings.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
This is not exportable, so you must call it like:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
    Archive::Zip::setErrorHandler( \&myErrorHandler );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
If no error handler is passed, resets handler to default.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
Returns old error handler.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
Note that if you call Carp::carp or a similar routine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
or if you're chaining to the default error handler
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
from your error handler, you may want to increment the number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
of caller levels that are skipped (do not just set it to a number):
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
    $Carp::CarpLevel++;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
sub setErrorHandler (&)	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
	my $errorHandler = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
	$errorHandler = \&Carp::carp if ! defined( $errorHandler );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
	my $oldErrorHandler = $Archive::Zip::ErrorHandler;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
	$Archive::Zip::ErrorHandler = $errorHandler;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
	return $oldErrorHandler;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
sub _printError	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
	my $string = join( ' ', @_, "\n" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
	my $oldCarpLevel = $Carp::CarpLevel;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
	$Carp::CarpLevel += 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
	&{ $ErrorHandler }( $string );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
	$Carp::CarpLevel = $oldCarpLevel;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
# This is called on format errors.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
sub _formatError	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
	shift if ref( $_[0] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
	_printError( 'format error:', @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
	return AZ_FORMAT_ERROR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
# This is called on IO errors.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
sub _ioError	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
	shift if ref( $_[0] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
	_printError( 'IO error:', @_, ':', $! );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
	return AZ_IO_ERROR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
# This is called on generic errors.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
sub _error	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
	shift if ref( $_[0] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
	_printError( 'error:', @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
	return AZ_ERROR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
# Called when a subclass should have implemented
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
# something but didn't
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
sub _subclassResponsibility 	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
	Carp::croak( "subclass Responsibility\n" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
# Try to set the given file handle or object into binary mode.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
sub _binmode	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
	return $fh->can( 'binmode' )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
		?	$fh->binmode()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
		:	binmode( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
# Attempt to guess whether file handle is seekable.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
sub _isSeekable	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
	my ($p0, $p1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
	my $seekable = 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
		( $p0 = $fh->tell() ) >= 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
		&& $fh->seek( 1, IO::Seekable::SEEK_CUR )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
		&& ( $p1 = $fh->tell() ) >= 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
		&& $p1 == $p0 + 1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
		&& $fh->seek( -1, IO::Seekable::SEEK_CUR )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
		&& $fh->tell() == $p0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
	return $seekable;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
# Return an opened IO::Handle
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
# my ( $status, fh ) = _newFileHandle( 'fileName', 'w' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
# Can take a filename, file handle, or ref to GLOB
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
# Or, if given something that is a ref but not an IO::Handle,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
# passes back the same thing.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
sub _newFileHandle	# Archive::Zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
	my $fd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
	my $status = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
	my $handle = IO::File->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
	if ( ref( $fd ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
		if ( $fd->isa( 'IO::Handle' ) or $fd->isa( 'GLOB' ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
			$status = $handle->fdopen( $fd, @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
			$handle = $fd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
		$status = $handle->open( $fd, @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
	return ( $status, $handle );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
# class Archive::Zip::Archive (concrete)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
# Generic ZIP archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
package Archive::Zip::Archive;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
use File::Path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
@ISA = qw( Archive::Zip );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :PKZIP_CONSTANTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
	:UTILITY_METHODS ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
# Note that this returns undef on read errors, else new zip object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
sub new	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
	my $self = bless( {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
		'diskNumber' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
		'diskNumberWithStartOfCentralDirectory' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
		'numberOfCentralDirectoriesOnThisDisk' => 0, # shld be # of members
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
		'numberOfCentralDirectories' => 0,	# shld be # of members
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
		'centralDirectorySize' => 0,	# must re-compute on write
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
		'centralDirectoryOffsetWRTStartingDiskNumber' => 0,	# must re-compute
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
		'zipfileComment' => ''
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
		}, $class );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
	$self->{'members'} = [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
	if ( @_ )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
		my $status = $self->read( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
		return $status == AZ_OK ? $self : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
=head2 Accessors
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
=item members()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
Return a copy of my members array
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
    my @members = $zip->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
sub members	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
{ @{ shift->{'members'} } }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
=item numberOfMembers()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
Return the number of members I have
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
sub numberOfMembers	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
{ scalar( shift->members() ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
=item memberNames()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
Return a list of the (internal) file names of my members
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
sub memberNames	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
	return map { $_->fileName() } $self->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
=item memberNamed( $string )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
Return ref to member whose filename equals given filename or undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
sub memberNamed	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
	my ( $self, $fileName ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
	my ( $retval ) = grep { $_->fileName() eq $fileName } $self->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
	return $retval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
=item membersMatching( $regex )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
Return array of members whose filenames match given regular
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
expression in list context.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
Returns number of matching members in scalar context.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
    my @textFileMembers = $zip->membersMatching( '.*\.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
    # or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
    my $numberOfTextFiles = $zip->membersMatching( '.*\.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
sub membersMatching	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
	my ( $self, $pattern ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
	return grep { $_->fileName() =~ /$pattern/ } $self->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
=item diskNumber()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
Return the disk that I start on.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
Not used for writing zips, but might be interesting if you read a zip in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   785
This had better be 0, as Archive::Zip does not handle multi-volume archives.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   786
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   787
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   788
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   789
sub diskNumber	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   790
{ shift->{'diskNumber'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   791
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   792
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   793
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   794
=item diskNumberWithStartOfCentralDirectory()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   795
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   796
Return the disk number that holds the beginning of the central directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   797
Not used for writing zips, but might be interesting if you read a zip in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   798
This had better be 0, as Archive::Zip does not handle multi-volume archives.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   799
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   800
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   801
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   802
sub diskNumberWithStartOfCentralDirectory	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   803
{ shift->{'diskNumberWithStartOfCentralDirectory'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   804
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   805
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   806
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   807
=item numberOfCentralDirectoriesOnThisDisk()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   808
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   809
Return the number of CD structures on this disk.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   810
Not used for writing zips, but might be interesting if you read a zip in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   811
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   812
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   813
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   814
sub numberOfCentralDirectoriesOnThisDisk	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   815
{ shift->{'numberOfCentralDirectoriesOnThisDisk'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   816
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   817
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   818
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   819
=item numberOfCentralDirectories()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   820
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   821
Return the number of CD structures in the whole zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   822
Not used for writing zips, but might be interesting if you read a zip in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   823
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   824
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   825
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   826
sub numberOfCentralDirectories	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   827
{ shift->{'numberOfCentralDirectories'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   828
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   829
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   830
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   831
=item centralDirectorySize()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   832
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   833
Returns central directory size, as read from an external zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   834
Not used for writing zips, but might be interesting if you read a zip in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   835
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   836
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   837
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   838
sub centralDirectorySize	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   839
{ shift->{'centralDirectorySize'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   840
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   841
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   842
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   843
=item centralDirectoryOffsetWRTStartingDiskNumber()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   844
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   845
Returns the offset into the zip file where the CD begins.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   846
Not used for writing zips, but might be interesting if you read a zip in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   847
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   848
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   849
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   850
sub centralDirectoryOffsetWRTStartingDiskNumber	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   851
{ shift->{'centralDirectoryOffsetWRTStartingDiskNumber'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   852
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   853
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   854
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   855
=item zipfileComment( [$string] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   856
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   857
Get or set the zipfile comment.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   858
Returns the old comment.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   859
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   860
    print $zip->zipfileComment();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   861
    $zip->zipfileComment( 'New Comment' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   862
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   863
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   864
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   865
sub zipfileComment	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   866
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   867
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   868
	my $comment = $self->{'zipfileComment'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   869
	if ( @_ )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   870
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   871
		$self->{'zipfileComment'} = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   872
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   873
	return $comment;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   874
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   875
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   876
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   877
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   878
=head2 Member Operations
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   879
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   880
Various operations on a zip file modify members.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   881
When a member is passed as an argument, you can either use a reference
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   882
to the member itself, or the name of a member. Of course, using the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   883
name requires that names be unique within a zip (this is not enforced).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   884
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   885
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   886
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   887
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   888
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   889
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   890
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   891
=item removeMember( $memberOrName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   892
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   893
Remove and return the given member, or match its name and remove it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   894
Returns undef if member name doesn't exist in this Zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   895
No-op if member does not belong to this zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   896
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   897
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   898
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   899
sub removeMember	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   900
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   901
	my ( $self, $member ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   902
	$member = $self->memberNamed( $member ) if ! ref( $member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   903
	return undef if ! $member;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   904
	my @newMembers = grep { $_ != $member } $self->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   905
	$self->{'members'} = \@newMembers;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   906
	return $member;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   907
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   908
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   909
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   910
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   911
=item replaceMember( $memberOrName, $newMember )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   912
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   913
Remove and return the given member, or match its name and remove it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   914
Replace with new member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   915
Returns undef if member name doesn't exist in this Zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   916
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   917
    my $member1 = $zip->removeMember( 'xyz' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   918
    my $member2 = $zip->replaceMember( 'abc', $member1 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   919
    # now, $member2 (named 'abc') is not in $zip,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   920
    # and $member1 (named 'xyz') is, having taken $member2's place.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   921
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   922
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   923
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   924
sub replaceMember	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   925
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   926
	my ( $self, $oldMember, $newMember ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   927
	$oldMember = $self->memberNamed( $oldMember ) if ! ref( $oldMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   928
	return undef if ! $oldMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   929
	my @newMembers
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   930
		= map { ( $_ == $oldMember ) ? $newMember : $_ } $self->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   931
	$self->{'members'} = \@newMembers;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   932
	return $oldMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   933
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   934
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   935
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   936
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   937
=item extractMember( $memberOrName [, $extractedName ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   938
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   939
Extract the given member, or match its name and extract it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   940
Returns undef if member doesn't exist in this Zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   941
If optional second arg is given, use it as the name of the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   942
extracted member. Otherwise, the internal filename of the member is used
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   943
as the name of the extracted file or directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   944
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   945
All necessary directories will be created.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   946
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   947
Returns C<AZ_OK> on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   948
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   949
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   950
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   951
sub extractMember	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   952
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   953
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   954
	my $member = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   955
	$member = $self->memberNamed( $member ) if ! ref( $member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   956
	return _error( 'member not found' ) if !$member;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   957
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   958
	$name = $member->fileName() if not $name;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   959
	my $dirName = dirname( $name );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   960
	mkpath( $dirName ) if ( ! -d $dirName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   961
	return _ioError( "can't create dir $dirName" ) if ( ! -d $dirName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   962
	return $member->extractToFileNamed( $name, @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   963
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   964
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   965
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   966
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   967
=item extractMemberWithoutPaths( $memberOrName [, $extractedName ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   968
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   969
Extract the given member, or match its name and extract it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   970
Does not use path information (extracts into the current directory).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   971
Returns undef if member doesn't exist in this Zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   972
If optional second arg is given, use it as the name of the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   973
extracted member (its paths will be deleted too).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   974
Otherwise, the internal filename of the member (minus paths) is used
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   975
as the name of the extracted file or directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   976
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   977
Returns C<AZ_OK> on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   978
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   979
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   980
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   981
sub extractMemberWithoutPaths	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   982
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   983
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   984
	my $member = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   985
	$member = $self->memberNamed( $member ) if ! ref( $member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   986
	return _error( 'member not found' ) if !$member;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   987
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   988
	$name = $member->fileName() if not $name;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   989
	$name = basename( $name );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   990
	return $member->extractToFileNamed( $name, @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   991
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   992
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   993
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   994
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   995
=item addMember( $member )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   996
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   997
Append a member (possibly from another zip file) to the zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   998
Returns the new member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   999
Generally, you will use addFile(), addDirectory(), addString(), or read()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1000
to add members.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1001
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1002
    # Move member named 'abc' to end of zip:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1003
    my $member = $zip->removeMember( 'abc' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1004
    $zip->addMember( $member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1005
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1006
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1007
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1008
sub addMember	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1009
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1010
	my ( $self, $newMember ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1011
	push( @{ $self->{'members'} }, $newMember ) if $newMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1012
	return $newMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1013
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1014
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1015
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1016
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1017
=item addFile( $fileName [, $newName ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1018
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1019
Append a member whose data comes from an external file,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1020
returning the member or undef.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1021
The member will have its file name set to the name of the external
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1022
file, and its desiredCompressionMethod set to COMPRESSION_DEFLATED.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1023
The file attributes and last modification time will be set from the file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1024
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1025
If the name given does not represent a readable plain file or symbolic link,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1026
undef will be returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1027
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1028
The text mode bit will be set if the contents appears to be text (as returned
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1029
by the C<-T> perl operator).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1030
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1031
The optional second argument sets the internal file name to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1032
something different than the given $fileName.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1033
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1034
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1035
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1036
sub addFile	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1037
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1038
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1039
	my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1040
	my $newName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1041
	my $newMember = $self->ZIPMEMBERCLASS->newFromFile( $fileName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1042
	if (defined($newMember))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1043
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1044
		$self->addMember( $newMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1045
		$newMember->fileName( $newName ) if defined( $newName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1046
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1047
	return $newMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1048
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1049
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1050
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1051
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1052
=item addString( $stringOrStringRef [, $name] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1053
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1054
Append a member created from the given string or string reference.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1055
The name is given by the optional second argument.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1056
Returns the new member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1057
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1058
The last modification time will be set to now,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1059
and the file attributes will be set to permissive defaults.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1060
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1061
    my $member = $zip->addString( 'This is a test', 'test.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1062
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1063
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1064
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1065
sub addString	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1066
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1067
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1068
	my $newMember = $self->ZIPMEMBERCLASS->newFromString( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1069
	return $self->addMember( $newMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1070
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1071
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1072
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1073
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1074
=item addDirectory( $directoryName [, $fileName ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1075
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1076
Append a member created from the given directory name.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1077
The directory name does not have to name an existing directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1078
If the named directory exists, the file modification time and permissions
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1079
are set from the existing directory, otherwise they are set to now and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1080
permissive default permissions.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1081
The optional second argument sets the name of the archive member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1082
(which defaults to $directoryName)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1083
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1084
Returns the new member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1085
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1086
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1087
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1088
sub addDirectory	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1089
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1090
	my ( $self, $name, $newName ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1091
	my $newMember = $self->ZIPMEMBERCLASS->newDirectoryNamed( $name );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1092
	$self->addMember( $newMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1093
	$newMember->fileName( $newName ) if defined( $newName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1094
	return $newMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1095
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1096
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1097
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1098
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1099
=item contents( $memberOrMemberName [, $newContents ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1100
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1101
Returns the uncompressed data for a particular member, or undef.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1102
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1103
    print "xyz.txt contains " . $zip->contents( 'xyz.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1104
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1105
Also can change the contents of a member:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1107
    $zip->contents( 'xyz.txt', 'This is the new contents' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1108
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1109
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1110
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1111
sub contents	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1112
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1113
	my ( $self, $member, $newContents ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1114
	$member = $self->memberNamed( $member ) if ! ref( $member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1115
	return undef if ! $member;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1116
	return $member->contents( $newContents );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1117
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1119
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1121
=item writeToFileNamed( $fileName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1122
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1123
Write a zip archive to named file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1124
Returns C<AZ_OK> on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1125
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1126
Note that if you use the same name as an existing
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1127
zip file that you read in, you will clobber ZipFileMembers.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1128
So instead, write to a different file name, then delete
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1129
the original.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1131
    my $status = $zip->writeToFileNamed( 'xx.zip' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1132
    die "error somewhere" if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1133
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1134
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1135
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1136
sub writeToFileNamed	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1137
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1138
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1139
	my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1140
	foreach my $member ( $self->members() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1141
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1142
		if ( $member->_usesFileNamed( $fileName ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1143
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1144
			return _error("$fileName is needed by member " 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1145
					. $member->fileName() 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1146
					. "; try renaming output file");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1147
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1148
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1149
	my ( $status, $fh ) = _newFileHandle( $fileName, 'w' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1150
	return _ioError( "Can't open $fileName for write" ) if !$status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1151
	my $retval = $self->writeToFileHandle( $fh, 1 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1152
	$fh->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1153
	return $retval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1154
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1156
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1158
=item writeToFileHandle( $fileHandle [, $seekable] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1160
Write a zip archive to a file handle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1161
Return AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1162
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1163
The optional second arg tells whether or not to try to seek backwards
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1164
to re-write headers.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1165
If not provided, it is set by testing seekability. This could fail
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1166
on some operating systems, though.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1167
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1168
    my $fh = IO::File->new( 'someFile.zip', 'w' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1169
    $zip->writeToFileHandle( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1171
If you pass a file handle that is not seekable (like if you're writing
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1172
to a pipe or a socket), pass a false as the second argument:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1173
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1174
    my $fh = IO::File->new( '| cat > somefile.zip', 'w' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1175
    $zip->writeToFileHandle( $fh, 0 );   # fh is not seekable
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1176
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1177
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1178
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1179
sub writeToFileHandle	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1180
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1181
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1182
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1183
	my $fhIsSeekable = @_ ? shift : _isSeekable( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1184
	_binmode( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1185
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1186
	my $offset = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1187
	foreach my $member ( $self->members() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1188
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1189
		$member->{'writeLocalHeaderRelativeOffset'} = $offset;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1190
		my $retval = $member->_writeToFileHandle( $fh, $fhIsSeekable );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1191
		$member->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1192
		return $retval if $retval != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1193
		$offset += $member->_localHeaderSize() + $member->_writeOffset();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1194
		$offset += $member->hasDataDescriptor() ? DATA_DESCRIPTOR_LENGTH : 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1195
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1196
	$self->{'writeCentralDirectoryOffset'} = $offset;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1197
	return $self->_writeCentralDirectory( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1198
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1199
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1200
# Returns next signature from given file handle, leaves
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1201
# file handle positioned afterwards.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1202
# In list context, returns ($status, $signature)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1204
sub _readSignature	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1205
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1206
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1207
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1208
	my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1209
	my $signatureData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1210
	$fh->read( $signatureData, SIGNATURE_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1211
		or return _ioError( "reading header signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1212
	my $signature = unpack( SIGNATURE_FORMAT, $signatureData );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1213
	my $status = AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1214
	if ( $signature != CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1215
			and $signature != LOCAL_FILE_HEADER_SIGNATURE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1216
			and $signature != END_OF_CENTRAL_DIRECTORY_SIGNATURE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1217
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1218
		$status = _formatError(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1219
			sprintf( "bad signature: 0x%08x at offset %d in file \"%s\"",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1220
				$signature, $fh->tell() - SIGNATURE_LENGTH, $fileName ) );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1221
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1222
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1223
	return ( $status, $signature );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1224
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1225
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1226
# Used only during writing
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1227
sub _writeCentralDirectoryOffset	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1228
{ shift->{'writeCentralDirectoryOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1230
sub _writeEOCDOffset	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1231
{ shift->{'writeEOCDOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1232
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1233
# Expects to have _writeEOCDOffset() set
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1234
sub _writeEndOfCentralDirectory	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1235
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1236
	my ( $self, $fh ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1237
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1238
	$fh->write( END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING, SIGNATURE_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1239
		or return _ioError( 'writing EOCD Signature' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1240
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1241
	my $header = pack( END_OF_CENTRAL_DIRECTORY_FORMAT,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1242
		0,	# {'diskNumber'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1243
		0,	# {'diskNumberWithStartOfCentralDirectory'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1244
		$self->numberOfMembers(),	# {'numberOfCentralDirectoriesOnThisDisk'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1245
		$self->numberOfMembers(),	# {'numberOfCentralDirectories'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1246
		$self->_writeEOCDOffset() - $self->_writeCentralDirectoryOffset(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1247
		$self->_writeCentralDirectoryOffset(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1248
		length( $self->zipfileComment() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1249
	 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1250
	$fh->write( $header, END_OF_CENTRAL_DIRECTORY_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1251
		or return _ioError( 'writing EOCD header' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1252
	if ( length( $self->zipfileComment() ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1253
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1254
		$fh->write( $self->zipfileComment(), length( $self->zipfileComment() ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1255
			or return _ioError( 'writing zipfile comment' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1256
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1257
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1258
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1259
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1260
sub _writeCentralDirectory	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1261
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1262
	my ( $self, $fh ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1263
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1264
	my $offset = $self->_writeCentralDirectoryOffset();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1265
	foreach my $member ( $self->members() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1266
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1267
		my $status = $member->_writeCentralDirectoryFileHeader( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1268
		return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1269
		$offset += $member->_centralDirectoryHeaderSize();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1270
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1271
	$self->{'writeEOCDOffset'} = $offset;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1272
	return $self->_writeEndOfCentralDirectory( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1273
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1274
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1275
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1276
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1277
=item read( $fileName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1278
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1279
Read zipfile headers from a zip file, appending new members.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1280
Returns C<AZ_OK> or error code.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1281
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1282
    my $zipFile = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1283
    my $status = $zipFile->read( '/some/FileName.zip' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1285
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1286
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1287
sub read	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1288
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1289
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1290
	my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1291
	return _error( 'No filename given' ) if ! $fileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1292
	my ( $status, $fh ) = _newFileHandle( $fileName, 'r' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1293
	return _ioError( "opening $fileName for read" ) if !$status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1294
	_binmode( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1295
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1296
	$status = $self->_findEndOfCentralDirectory( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1297
	return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1299
	my $eocdPosition = $fh->tell();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1301
	$status = $self->_readEndOfCentralDirectory( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1302
	return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1303
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1304
	$fh->seek( $eocdPosition - $self->centralDirectorySize(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1305
		IO::Seekable::SEEK_SET )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1306
			or return _ioError( "Can't seek $fileName" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1307
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1308
	for ( ;; )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1309
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1310
		my $newMember = 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1311
			$self->ZIPMEMBERCLASS->_newFromZipFile( $fh, $fileName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1312
		my $signature;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1313
		( $status, $signature ) = $self->_readSignature( $fh, $fileName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1314
		return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1315
		last if $signature == END_OF_CENTRAL_DIRECTORY_SIGNATURE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1316
		$status = $newMember->_readCentralDirectoryFileHeader();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1317
		return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1318
		$status = $newMember->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1319
		return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1320
		$newMember->_becomeDirectoryIfNecessary();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1321
		push( @{ $self->{'members'} }, $newMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1322
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1323
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1324
	$fh->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1325
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1326
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1327
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1328
# Read EOCD, starting from position before signature.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1329
# Return AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1330
sub _readEndOfCentralDirectory	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1331
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1332
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1333
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1334
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1335
	# Skip past signature
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1336
	$fh->seek( SIGNATURE_LENGTH, IO::Seekable::SEEK_CUR )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1337
		or return _ioError( "Can't seek past EOCD signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1339
	my $header = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1340
	$fh->read( $header, END_OF_CENTRAL_DIRECTORY_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1341
		or return _ioError( "reading end of central directory" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1342
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1343
	my $zipfileCommentLength;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1344
	(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1345
		$self->{'diskNumber'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1346
		$self->{'diskNumberWithStartOfCentralDirectory'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1347
		$self->{'numberOfCentralDirectoriesOnThisDisk'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1348
		$self->{'numberOfCentralDirectories'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1349
		$self->{'centralDirectorySize'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1350
		$self->{'centralDirectoryOffsetWRTStartingDiskNumber'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1351
		$zipfileCommentLength
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1352
	 ) = unpack( END_OF_CENTRAL_DIRECTORY_FORMAT, $header );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1353
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1354
	if ( $zipfileCommentLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1355
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1356
		my $zipfileComment = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1357
		$fh->read( $zipfileComment, $zipfileCommentLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1358
			or return _ioError( "reading zipfile comment" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1359
		$self->{'zipfileComment'} = $zipfileComment;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1360
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1361
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1362
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1363
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1364
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1365
# Seek in my file to the end, then read backwards until we find the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1366
# signature of the central directory record. Leave the file positioned right
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1367
# before the signature. Returns AZ_OK if success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1368
sub _findEndOfCentralDirectory	# Archive::Zip::Archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1369
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1370
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1371
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1372
	my $data = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1373
	$fh->seek( 0, IO::Seekable::SEEK_END )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1374
		or return _ioError( "seeking to end" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1375
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1376
	my $fileLength = $fh->tell();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1377
	if ( $fileLength < END_OF_CENTRAL_DIRECTORY_LENGTH + 4 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1378
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1379
		return _formatError( "file is too short" )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1380
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1381
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1382
	my $seekOffset = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1383
	my $pos = -1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1384
	for ( ;; )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1385
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1386
		$seekOffset += 512;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1387
		$seekOffset = $fileLength if ( $seekOffset > $fileLength );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1388
		$fh->seek( -$seekOffset, IO::Seekable::SEEK_END )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1389
			or return _ioError( "seek failed" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1390
		$fh->read( $data, $seekOffset )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1391
			or return _ioError( "read failed" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1392
		$pos = rindex( $data, END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1393
		last if ( $pos > 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1394
			or $seekOffset == $fileLength
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1395
			or $seekOffset >= $Archive::Zip::ChunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1396
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1397
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1398
	if ( $pos >= 0 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1399
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1400
		$fh->seek( $pos - $seekOffset, IO::Seekable::SEEK_CUR )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1401
			or return _ioError( "seeking to EOCD" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1402
		return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1403
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1404
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1405
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1406
		return _formatError( "can't find EOCD signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1407
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1408
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1409
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1410
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1411
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1412
=head1 MEMBER OPERATIONS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1413
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1414
=head2 Class Methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1415
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1416
Several constructors allow you to construct members without adding
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1417
them to a zip archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1418
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1419
These work the same as the addFile(), addDirectory(), and addString()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1420
zip instance methods described above, but they don't add the new members
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1421
to a zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1422
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1423
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1424
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1425
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1426
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1427
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1428
# class Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1429
# A generic member of an archive ( abstract )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1430
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1431
package Archive::Zip::Member;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1432
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1433
@ISA = qw ( Archive::Zip );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1434
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1435
BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :PKZIP_CONSTANTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1436
	:UTILITY_METHODS ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1437
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1438
use Time::Local ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1439
use Compress::Zlib qw( Z_OK Z_STREAM_END MAX_WBITS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1440
use File::Path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1441
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1442
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1443
use constant ZIPFILEMEMBERCLASS	=> 'Archive::Zip::ZipFileMember';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1444
use constant NEWFILEMEMBERCLASS	=> 'Archive::Zip::NewFileMember';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1445
use constant STRINGMEMBERCLASS	=> 'Archive::Zip::StringMember';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1446
use constant DIRECTORYMEMBERCLASS	=> 'Archive::Zip::DirectoryMember';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1447
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1448
# Unix perms for default creation of files/dirs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1449
use constant DEFAULT_DIRECTORY_PERMISSIONS => 040755;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1450
use constant DEFAULT_FILE_PERMISSIONS => 0100666;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1451
use constant DIRECTORY_ATTRIB => 040000;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1452
use constant FILE_ATTRIB => 0100000;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1453
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1454
# Returns self if successful, else undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1455
# Assumes that fh is positioned at beginning of central directory file header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1456
# Leaves fh positioned immediately after file header or EOCD signature.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1457
sub _newFromZipFile # Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1458
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1459
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1460
	my $self = $class->ZIPFILEMEMBERCLASS->_newFromZipFile( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1461
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1462
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1463
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1464
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1465
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1466
=item Archive::Zip::Member->newFromString( $stringOrStringRef [, $fileName] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1467
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1468
Construct a new member from the given string. Returns undef on error.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1469
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1470
    my $member = Archive::Zip::Member->newFromString( 'This is a test',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1471
                                                     'xyz.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1472
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1473
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1474
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1475
sub newFromString	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1476
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1477
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1478
	my $self = $class->STRINGMEMBERCLASS->_newFromString( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1479
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1480
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1481
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1482
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1483
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1484
=item newFromFile( $fileName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1485
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1486
Construct a new member from the given file. Returns undef on error.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1487
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1488
    my $member = Archive::Zip::Member->newFromFile( 'xyz.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1489
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1490
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1491
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1492
sub newFromFile	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1493
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1494
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1495
	my $self = $class->NEWFILEMEMBERCLASS->_newFromFileNamed( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1496
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1497
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1498
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1499
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1500
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1501
=item newDirectoryNamed( $directoryName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1502
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1503
Construct a new member from the given directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1504
Returns undef on error.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1505
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1506
    my $member = Archive::Zip::Member->newDirectoryNamed( 'CVS/' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1507
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1508
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1509
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1510
sub newDirectoryNamed # Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1511
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1512
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1513
	my $self = $class->DIRECTORYMEMBERCLASS->_newNamed( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1514
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1515
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1516
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1517
sub new	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1518
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1519
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1520
	my $self = {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1521
		'lastModFileDateTime' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1522
		'fileAttributeFormat' => FA_UNIX,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1523
		'versionMadeBy' => 20,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1524
		'versionNeededToExtract' => 20,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1525
		'bitFlag' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1526
		'compressionMethod' => COMPRESSION_STORED,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1527
		'desiredCompressionMethod' => COMPRESSION_STORED,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1528
		'desiredCompressionLevel' => COMPRESSION_LEVEL_NONE,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1529
		'internalFileAttributes' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1530
		'externalFileAttributes' => 0,	# set later
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1531
		'fileName' => '',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1532
		'cdExtraField' => '',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1533
		'localExtraField' => '',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1534
		'fileComment' => '',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1535
		'crc32' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1536
		'compressedSize' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1537
		'uncompressedSize' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1538
		@_
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1539
	};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1540
	bless( $self, $class );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1541
	$self->unixFileAttributes( $self->DEFAULT_FILE_PERMISSIONS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1542
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1543
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1544
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1545
sub _becomeDirectoryIfNecessary	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1546
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1547
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1548
	$self->_become( DIRECTORYMEMBERCLASS )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1549
		if $self->isDirectory();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1550
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1551
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1552
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1553
# Morph into given class (do whatever cleanup I need to do)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1554
sub _become	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1555
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1556
	return bless( $_[0], $_[1] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1557
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1558
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1559
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1560
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1561
=head2 Simple accessors
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1562
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1563
These methods get (and/or set) member attribute values.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1564
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1565
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1566
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1567
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1568
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1569
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1570
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1571
=item versionMadeBy()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1572
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1573
Gets the field from my member header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1574
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1575
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1576
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1577
sub versionMadeBy	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1578
{ shift->{'versionMadeBy'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1579
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1580
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1581
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1582
=item fileAttributeFormat( [$format] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1583
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1584
Gets or sets the field from the member header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1585
These are C<FA_*> values.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1586
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1587
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1588
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1589
sub fileAttributeFormat	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1590
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1591
	( $#_ > 0 ) ? ( $_[0]->{'fileAttributeFormat'} = $_[1] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1592
		: $_[0]->{'fileAttributeFormat'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1593
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1594
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1595
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1596
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1597
=item versionNeededToExtract()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1598
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1599
Gets the field from my member header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1600
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1601
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1603
sub versionNeededToExtract	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1604
{ shift->{'versionNeededToExtract'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1605
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1606
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1607
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1608
=item bitFlag()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1609
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1610
Gets the general purpose bit field from my member header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1611
This is where the C<GPBF_*> bits live.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1612
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1613
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1614
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1615
sub bitFlag	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1616
{ shift->{'bitFlag'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1617
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1618
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1619
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1620
=item compressionMethod()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1621
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1622
Returns my compression method. This is the method that is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1623
currently being used to compress my data.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1624
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1625
This will be COMPRESSION_STORED for added string or file members,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1626
or any of the C<COMPRESSION_*> values for members from a zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1627
However, this module can only handle members whose data is in
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1628
COMPRESSION_STORED or COMPRESSION_DEFLATED format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1629
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1630
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1631
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1632
sub compressionMethod	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1633
{ shift->{'compressionMethod'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1634
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1635
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1636
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1637
=item desiredCompressionMethod( [$method] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1638
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1639
Get or set my desiredCompressionMethod
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1640
This is the method that will be used to write.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1641
Returns prior desiredCompressionMethod.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1642
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1643
Only COMPRESSION_DEFLATED or COMPRESSION_STORED are valid arguments.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1644
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1645
Changing to COMPRESSION_STORED will change my desiredCompressionLevel
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1646
to 0; changing to COMPRESSION_DEFLATED will change my
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1647
desiredCompressionLevel to COMPRESSION_LEVEL_DEFAULT.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1648
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1649
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1650
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1651
sub desiredCompressionMethod	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1652
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1653
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1654
	my $newDesiredCompressionMethod = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1655
	my $oldDesiredCompressionMethod = $self->{'desiredCompressionMethod'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1656
	if ( defined( $newDesiredCompressionMethod ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1657
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1658
		$self->{'desiredCompressionMethod'} = $newDesiredCompressionMethod;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1659
		if ( $newDesiredCompressionMethod == COMPRESSION_STORED )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1660
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1661
			$self->{'desiredCompressionLevel'} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1662
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1663
		elsif ( $oldDesiredCompressionMethod == COMPRESSION_STORED )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1664
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1665
			$self->{'desiredCompressionLevel'} = COMPRESSION_LEVEL_DEFAULT;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1666
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1667
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1668
	return $oldDesiredCompressionMethod;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1669
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1670
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1671
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1672
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1673
=item desiredCompressionLevel( [$method] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1674
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1675
Get or set my desiredCompressionLevel
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1676
This is the method that will be used to write.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1677
Returns prior desiredCompressionLevel.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1678
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1679
Valid arguments are 0 through 9, COMPRESSION_LEVEL_NONE,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1680
COMPRESSION_LEVEL_DEFAULT, COMPRESSION_LEVEL_BEST_COMPRESSION, and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1681
COMPRESSION_LEVEL_FASTEST.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1682
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1683
0 or COMPRESSION_LEVEL_NONE will change the desiredCompressionMethod
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1684
to COMPRESSION_STORED. All other arguments will change the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1685
desiredCompressionMethod to COMPRESSION_DEFLATED.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1686
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1687
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1688
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1689
sub desiredCompressionLevel	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1690
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1691
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1692
	my $newDesiredCompressionLevel = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1693
	my $oldDesiredCompressionLevel = $self->{'desiredCompressionLevel'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1694
	if ( defined( $newDesiredCompressionLevel ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1695
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1696
		$self->{'desiredCompressionLevel'} = $newDesiredCompressionLevel;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1697
		$self->{'desiredCompressionMethod'} = ( $newDesiredCompressionLevel
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1698
			? COMPRESSION_DEFLATED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1699
			: COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1700
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1701
	return $oldDesiredCompressionLevel;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1702
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1703
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1704
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1705
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1706
=item fileName()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1708
Get or set my internal filename.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1709
Returns the (possibly new) filename.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1710
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1711
Names will have backslashes converted to forward slashes,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1712
and will have multiple consecutive slashes converted to single ones.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1713
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1714
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1715
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1716
sub fileName	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1717
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1718
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1719
	my $newName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1720
	if ( $newName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1721
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1722
		$newName =~ s{[\\/]+}{/}g;	# deal with dos/windoze problems
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1723
		$self->{'fileName'} = $newName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1724
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1725
	return $self->{'fileName'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1726
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1727
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1728
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1729
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1730
=item lastModFileDateTime()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1731
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1732
Return my last modification date/time stamp in MS-DOS format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1733
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1734
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1735
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1736
sub lastModFileDateTime	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1737
{ shift->{'lastModFileDateTime'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1738
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1739
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1740
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1741
=item lastModTime()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1742
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1743
Return my last modification date/time stamp,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1744
converted to unix localtime format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1745
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1746
    print "Mod Time: " . scalar( localtime( $member->lastModTime() ) );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1747
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1748
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1749
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1750
sub lastModTime	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1751
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1752
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1753
	return _dosToUnixTime( $self->lastModFileDateTime() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1754
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1755
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1756
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1757
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1758
=item setLastModFileDateTimeFromUnix()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1759
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1760
Set my lastModFileDateTime from the given unix time.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1761
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1762
    $member->setLastModFileDateTimeFromUnix( time() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1763
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1764
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1765
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1766
sub setLastModFileDateTimeFromUnix	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1767
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1768
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1769
	my $time_t = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1770
	$self->{'lastModFileDateTime'} = _unixToDosTime( $time_t );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1771
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1772
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1773
# Convert DOS date/time format to unix time_t format
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1774
# NOT AN OBJECT METHOD!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1775
sub _dosToUnixTime	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1776
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1777
	my $dt = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1778
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1779
	my $year = ( ( $dt >> 25 ) & 0x7f ) + 80;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1780
	my $mon  = ( ( $dt >> 21 ) & 0x0f ) - 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1781
	my $mday = ( ( $dt >> 16 ) & 0x1f );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1782
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1783
	my $hour = ( ( $dt >> 11 ) & 0x1f );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1784
	my $min  = ( ( $dt >> 5 ) & 0x3f );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1785
	my $sec  = ( ( $dt << 1 ) & 0x3e );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1786
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1787
	my $time_t = Time::Local::timelocal( $sec, $min, $hour, $mday, $mon, $year );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1788
	return $time_t;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1789
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1790
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1791
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1792
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1793
=item internalFileAttributes()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1794
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1795
Return the internal file attributes field from the zip header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1796
This is only set for members read from a zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1797
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1798
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1799
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1800
sub internalFileAttributes	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1801
{ shift->{'internalFileAttributes'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1802
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1803
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1804
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1805
=item externalFileAttributes()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1806
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1807
Return member attributes as read from the ZIP file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1808
Note that these are NOT UNIX!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1809
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1810
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1811
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1812
sub externalFileAttributes	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1813
{ shift->{'externalFileAttributes'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1814
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1815
# Convert UNIX permissions into proper value for zip file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1816
# NOT A METHOD!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1817
sub _mapPermissionsFromUnix	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1818
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1819
	my $perms = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1820
	return $perms << 16;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1821
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1822
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1823
# Convert ZIP permissions into Unix ones
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1824
# NOT A METHOD!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1825
sub _mapPermissionsToUnix	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1826
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1827
	my $perms = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1828
	return $perms >> 16;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1829
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1830
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1831
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1832
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1833
=item unixFileAttributes( [$newAttributes] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1834
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1835
Get or set the member's file attributes using UNIX file attributes.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1836
Returns old attributes.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1837
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1838
    my $oldAttribs = $member->unixFileAttributes( 0666 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1839
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1840
Note that the return value has more than just the file permissions,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1841
so you will have to mask off the lowest bits for comparisions.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1842
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1843
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1844
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1845
sub unixFileAttributes	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1846
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1847
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1848
	my $oldPerms = _mapPermissionsToUnix( $self->{'externalFileAttributes'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1849
	if ( @_ )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1850
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1851
		my $perms = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1852
		if ( $self->isDirectory() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1853
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1854
			$perms &= ~FILE_ATTRIB;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1855
			$perms |= DIRECTORY_ATTRIB;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1856
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1857
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1858
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1859
			$perms &= ~DIRECTORY_ATTRIB;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1860
			$perms |= FILE_ATTRIB;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1861
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1862
		$self->{'externalFileAttributes'} = _mapPermissionsFromUnix( $perms);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1863
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1864
	return $oldPerms;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1865
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1866
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1867
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1868
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1869
=item localExtraField( [$newField] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1870
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1871
Gets or sets the extra field that was read from the local header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1872
This is not set for a member from a zip file until after the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1873
member has been written out.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1874
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1875
The extra field must be in the proper format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1876
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1877
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1878
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1879
sub localExtraField	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1880
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1881
	( $#_ > 0 ) ? ( $_[0]->{'localExtraField'} = $_[1] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1882
		: $_[0]->{'localExtraField'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1883
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1884
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1885
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1886
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1887
=item cdExtraField( [$newField] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1888
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1889
Gets or sets the extra field that was read from the central directory header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1890
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1891
The extra field must be in the proper format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1892
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1893
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1894
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1895
sub cdExtraField	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1896
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1897
	( $#_ > 0 ) ? ( $_[0]->{'cdExtraField'} = $_[1] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1898
		: $_[0]->{'cdExtraField'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1899
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1900
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1901
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1902
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1903
=item extraFields()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1904
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1905
Return both local and CD extra fields, concatenated.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1906
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1907
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1908
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1909
sub extraFields	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1910
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1911
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1912
	return $self->localExtraField() . $self->cdExtraField();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1913
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1914
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1915
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1916
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1917
=item fileComment( [$newComment] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1918
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1919
Get or set the member's file comment.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1920
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1921
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1922
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1923
sub fileComment	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1924
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1925
	( $#_ > 0 ) ? ( $_[0]->{'fileComment'} = $_[1] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1926
		: $_[0]->{'fileComment'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1927
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1928
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1929
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1930
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1931
=item hasDataDescriptor()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1932
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1933
Get or set the data descriptor flag.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1934
If this is set, the local header will not necessarily
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1935
have the correct data sizes. Instead, a small structure
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1936
will be stored at the end of the member data with these
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1937
values.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1938
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1939
This should be transparent in normal operation.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1940
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1941
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1942
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1943
sub hasDataDescriptor	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1944
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1945
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1946
	if ( @_ )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1947
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1948
		my $shouldHave = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1949
		if ( $shouldHave )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1950
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1951
			$self->{'bitFlag'} |= GPBF_HAS_DATA_DESCRIPTOR_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1952
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1953
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1954
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1955
			$self->{'bitFlag'} &= ~GPBF_HAS_DATA_DESCRIPTOR_MASK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1956
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1957
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1958
	return $self->{'bitFlag'} & GPBF_HAS_DATA_DESCRIPTOR_MASK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1959
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1960
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1961
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1962
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1963
=item crc32()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1964
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1965
Return the CRC-32 value for this member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1966
This will not be set for members that were constructed from strings
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1967
or external files until after the member has been written.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1968
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1969
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1970
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1971
sub crc32	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1972
{ shift->{'crc32'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1973
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1974
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1975
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1976
=item crc32String()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1977
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1978
Return the CRC-32 value for this member as an 8 character printable
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1979
hex string.  This will not be set for members that were constructed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1980
from strings or external files until after the member has been written.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1981
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1982
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1983
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1984
sub crc32String	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1985
{ sprintf( "%08x", shift->{'crc32'} ); }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1986
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1987
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1988
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1989
=item compressedSize()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1990
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1991
Return the compressed size for this member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1992
This will not be set for members that were constructed from strings
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1993
or external files until after the member has been written.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1994
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1995
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1996
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1997
sub compressedSize	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1998
{ shift->{'compressedSize'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1999
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2000
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2001
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2002
=item uncompressedSize()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2003
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2004
Return the uncompressed size for this member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2005
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2006
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2007
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2008
sub uncompressedSize	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2009
{ shift->{'uncompressedSize'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2010
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2011
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2012
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2013
=item isEncrypted()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2014
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2015
Return true if this member is encrypted.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2016
The Archive::Zip module does not currently create or extract
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2017
encrypted members.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2018
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2019
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2020
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2021
sub isEncrypted	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2022
{ shift->bitFlag() & GPBF_ENCRYPTED_MASK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2023
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2024
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2025
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2026
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2027
=item isTextFile( [$flag] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2028
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2029
Returns true if I am a text file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2030
Also can set the status if given an argument (then returns old state).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2031
Note that this module does not currently do anything with this flag
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2032
upon extraction or storage.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2033
That is, bytes are stored in native format whether or not they came
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2034
from a text file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2035
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2036
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2037
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2038
sub isTextFile	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2039
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2040
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2041
	my $bit = $self->internalFileAttributes() & IFA_TEXT_FILE_MASK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2042
	if ( @_ )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2043
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2044
		my $flag = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2045
		$self->{'internalFileAttributes'} &= ~IFA_TEXT_FILE_MASK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2046
		$self->{'internalFileAttributes'} |=
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2047
			( $flag ? IFA_TEXT_FILE : IFA_BINARY_FILE );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2048
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2049
	return $bit == IFA_TEXT_FILE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2050
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2051
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2052
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2053
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2054
=item isBinaryFile()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2055
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2056
Returns true if I am a binary file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2057
Also can set the status if given an argument (then returns old state).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2058
Note that this module does not currently do anything with this flag
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2059
upon extraction or storage.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2060
That is, bytes are stored in native format whether or not they came
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2061
from a text file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2062
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2063
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2064
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2065
sub isBinaryFile	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2066
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2067
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2068
	my $bit = $self->internalFileAttributes() & IFA_TEXT_FILE_MASK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2069
	if ( @_ )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2070
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2071
		my $flag = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2072
		$self->{'internalFileAttributes'} &= ~IFA_TEXT_FILE_MASK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2073
		$self->{'internalFileAttributes'} |=
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2074
			( $flag ? IFA_BINARY_FILE : IFA_TEXT_FILE );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2075
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2076
	return $bit == IFA_BINARY_FILE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2077
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2078
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2079
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2080
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2081
=item extractToFileNamed( $fileName )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2082
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2083
Extract me to a file with the given name.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2084
The file will be created with default modes.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2085
Directories will be created as needed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2086
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2087
Returns AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2088
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2089
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2090
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2091
sub extractToFileNamed	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2092
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2093
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2094
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2095
	return _error( "encryption unsupported" ) if $self->isEncrypted();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2096
	mkpath( dirname( $name ) );	# croaks on error
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2097
	my ( $status, $fh ) = _newFileHandle( $name, 'w' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2098
	return _ioError( "Can't open file $name for write" ) if !$status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2099
	my $retval = $self->extractToFileHandle( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2100
	$fh->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2101
	return $retval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2102
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2103
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2104
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2105
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2106
=item isDirectory()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2107
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2108
Returns true if I am a directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2110
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2111
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2112
sub isDirectory	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2113
{ return 0 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2114
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2115
# The following are used when copying data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2116
sub _writeOffset	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2117
{ shift->{'writeOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2119
sub _readOffset	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2120
{ shift->{'readOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2121
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2122
sub _writeLocalHeaderRelativeOffset	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2123
{ shift->{'writeLocalHeaderRelativeOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2124
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2125
sub _dataEnded	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2126
{ shift->{'dataEnded'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2127
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2128
sub _readDataRemaining	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2129
{ shift->{'readDataRemaining'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2131
sub _inflater	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2132
{ shift->{'inflater'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2133
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2134
sub _deflater	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2135
{ shift->{'deflater'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2137
# Return the total size of my local header
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2138
sub _localHeaderSize	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2139
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2140
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2141
	return SIGNATURE_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2142
		+ LOCAL_FILE_HEADER_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2143
		+ length( $self->fileName() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2144
		+ length( $self->localExtraField() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2145
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2146
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2147
# Return the total size of my CD header
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2148
sub _centralDirectoryHeaderSize	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2149
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2150
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2151
	return SIGNATURE_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2152
		+ CENTRAL_DIRECTORY_FILE_HEADER_LENGTH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2153
		+ length( $self->fileName() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2154
		+ length( $self->cdExtraField() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2155
		+ length( $self->fileComment() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2156
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2158
# convert a unix time to DOS date/time
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2159
# NOT AN OBJECT METHOD!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2160
sub _unixToDosTime	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2161
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2162
	my $time_t = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2163
	my ( $sec,$min,$hour,$mday,$mon,$year ) = localtime( $time_t );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2164
	my $dt = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2165
	$dt += ( $sec >> 1 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2166
	$dt += ( $min << 5 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2167
	$dt += ( $hour << 11 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2168
	$dt += ( $mday << 16 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2169
	$dt += ( ( $mon + 1 ) << 21 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2170
	$dt += ( ( $year - 80 ) << 25 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2171
	return $dt;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2172
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2173
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2174
# Write my local header to a file handle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2175
# Stores the offset to the start of the header in my
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2176
# writeLocalHeaderRelativeOffset member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2177
# Returns AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2178
sub _writeLocalFileHeader	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2179
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2180
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2181
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2183
	my $signatureData = pack( SIGNATURE_FORMAT, LOCAL_FILE_HEADER_SIGNATURE );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2184
	$fh->write( $signatureData, SIGNATURE_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2185
		or return _ioError( "writing local header signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2186
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2187
	my $header = pack( LOCAL_FILE_HEADER_FORMAT,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2188
		$self->versionNeededToExtract(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2189
		$self->bitFlag(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2190
		$self->desiredCompressionMethod(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2191
		$self->lastModFileDateTime(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2192
		$self->crc32(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2193
		$self->compressedSize(),		# may need to be re-written later
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2194
		$self->uncompressedSize(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2195
		length( $self->fileName() ),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2196
		length( $self->localExtraField() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2197
		 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2198
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2199
	$fh->write( $header, LOCAL_FILE_HEADER_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2200
		or return _ioError( "writing local header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2201
	if ( length( $self->fileName() ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2202
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2203
		$fh->write( $self->fileName(), length( $self->fileName() ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2204
			or return _ioError( "writing local header filename" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2205
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2206
	if ( length( $self->localExtraField() ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2207
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2208
		$fh->write( $self->localExtraField(), length( $self->localExtraField() ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2209
			or return _ioError( "writing local header signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2210
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2211
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2212
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2213
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2214
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2215
sub _writeCentralDirectoryFileHeader	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2216
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2217
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2218
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2219
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2220
	my $sigData = pack( SIGNATURE_FORMAT,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2221
		CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2222
	$fh->write( $sigData, SIGNATURE_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2223
		or return _ioError( "writing central directory header signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2224
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2225
	my $fileNameLength = length( $self->fileName() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2226
	my $extraFieldLength = length( $self->cdExtraField() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2227
	my $fileCommentLength = length( $self->fileComment() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2228
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2229
	my $header = pack( CENTRAL_DIRECTORY_FILE_HEADER_FORMAT,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2230
		$self->versionMadeBy(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2231
		$self->fileAttributeFormat(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2232
		$self->versionNeededToExtract(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2233
		$self->bitFlag(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2234
		$self->desiredCompressionMethod(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2235
		$self->lastModFileDateTime(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2236
		$self->crc32(),			# these three fields should have been updated
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2237
		$self->_writeOffset(),	# by writing the data stream out
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2238
		$self->uncompressedSize(),	#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2239
		$fileNameLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2240
		$extraFieldLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2241
		$fileCommentLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2242
		0,						# {'diskNumberStart'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2243
		$self->internalFileAttributes(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2244
		$self->externalFileAttributes(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2245
		$self->_writeLocalHeaderRelativeOffset()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2246
	 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2247
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2248
	$fh->write( $header, CENTRAL_DIRECTORY_FILE_HEADER_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2249
		or return _ioError( "writing central directory header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2250
	if ( $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2251
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2252
		$fh->write( $self->fileName(), $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2253
			or return _ioError( "writing central directory header signature" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2254
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2255
	if ( $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2256
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2257
		$fh->write( $self->cdExtraField(), $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2258
			or return _ioError( "writing central directory extra field" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2259
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2260
	if ( $fileCommentLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2261
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2262
		$fh->write( $self->fileComment(), $fileCommentLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2263
			or return _ioError( "writing central directory file comment" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2264
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2265
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2266
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2267
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2268
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2269
# This writes a data descriptor to the given file handle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2270
# Assumes that crc32, writeOffset, and uncompressedSize are
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2271
# set correctly (they should be after a write).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2272
# Further, the local file header should have the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2273
# GPBF_HAS_DATA_DESCRIPTOR_MASK bit set.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2274
sub _writeDataDescriptor	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2275
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2276
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2277
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2278
	my $header = pack( DATA_DESCRIPTOR_FORMAT,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2279
		$self->crc32(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2280
		$self->_writeOffset(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2281
		$self->uncompressedSize()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2282
	 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2283
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2284
	$fh->write( $header, DATA_DESCRIPTOR_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2285
		or return _ioError( "writing data descriptor" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2286
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2287
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2288
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2289
# Re-writes the local file header with new crc32 and compressedSize fields.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2290
# To be called after writing the data stream.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2291
# Assumes that filename and extraField sizes didn't change since last written.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2292
sub _refreshLocalFileHeader	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2293
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2294
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2295
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2297
	my $here = $fh->tell();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2298
	$fh->seek( $self->_writeLocalHeaderRelativeOffset() + SIGNATURE_LENGTH,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2299
		IO::Seekable::SEEK_SET )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2300
			or return _ioError( "seeking to rewrite local header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2301
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2302
	my $header = pack( LOCAL_FILE_HEADER_FORMAT,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2303
		$self->versionNeededToExtract(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2304
		$self->bitFlag(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2305
		$self->desiredCompressionMethod(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2306
		$self->lastModFileDateTime(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2307
		$self->crc32(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2308
		$self->_writeOffset(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2309
		$self->uncompressedSize(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2310
		length( $self->fileName() ),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2311
		length( $self->localExtraField() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2312
		 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2313
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2314
	$fh->write( $header, LOCAL_FILE_HEADER_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2315
		or return _ioError( "re-writing local header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2316
	$fh->seek( $here, IO::Seekable::SEEK_SET )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2317
			or return _ioError( "seeking after rewrite of local header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2318
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2319
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2320
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2322
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2323
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2324
=head2 Low-level member data reading
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2325
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2326
It is possible to use lower-level routines to access member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2327
data streams, rather than the extract* methods and contents().
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2328
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2329
For instance, here is how to print the uncompressed contents
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2330
of a member in chunks using these methods:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2331
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2332
    my ( $member, $status, $bufferRef );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2333
    $member = $zip->memberNamed( 'xyz.txt' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2334
    $member->desiredCompressionMethod( COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2335
    $status = $member->rewindData();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2336
    die "error $status" if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2337
    while ( ! $member->readIsDone() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2338
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2339
        ( $bufferRef, $status ) = $member->readChunk();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2340
        die "error $status" if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2341
        # do something with $bufferRef:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2342
        print $$bufferRef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2343
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2344
    $member->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2345
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2346
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2348
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2350
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2351
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2352
=item readChunk( [$chunkSize] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2353
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2354
This reads the next chunk of given size from the member's data stream and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2355
compresses or uncompresses it as necessary, returning a reference to the bytes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2356
read and a status.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2357
If size argument is not given, defaults to global set by
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2358
Archive::Zip::setChunkSize.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2359
Status is AZ_OK on success. Returns C<( \$bytes, $status)>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2360
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2361
    my ( $outRef, $status ) = $self->readChunk();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2362
    print $$outRef if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2363
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2364
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2365
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2366
sub readChunk	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2367
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2368
	my ( $self, $chunkSize ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2369
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2370
	if ( $self->readIsDone() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2371
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2372
		$self->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2373
		my $dummy = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2374
		return ( \$dummy, AZ_STREAM_END );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2375
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2376
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2377
	$chunkSize = $Archive::Zip::ChunkSize if not defined( $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2378
	$chunkSize = $self->_readDataRemaining()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2379
		if $chunkSize > $self->_readDataRemaining();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2380
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2381
	my $buffer = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2382
	my $outputRef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2383
	my ( $bytesRead, $status) = $self->_readRawChunk( \$buffer, $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2384
	return ( \$buffer, $status) if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2385
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2386
	$self->{'readDataRemaining'} -= $bytesRead;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2387
	$self->{'readOffset'} += $bytesRead;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2388
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2389
	if ( $self->compressionMethod() == COMPRESSION_STORED )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2390
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2391
		$self->{'crc32'} = $self->computeCRC32( $buffer, $self->{'crc32'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2392
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2393
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2394
	( $outputRef, $status) = &{$self->{'chunkHandler'}}( $self, \$buffer );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2395
	$self->{'writeOffset'} += length( $$outputRef );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2396
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2397
	$self->endRead()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2398
		if $self->readIsDone();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2399
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2400
	return ( $outputRef, $status);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2401
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2402
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2403
# Read the next raw chunk of my data. Subclasses MUST implement.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2404
#	my ( $bytesRead, $status) = $self->_readRawChunk( \$buffer, $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2405
sub _readRawChunk	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2406
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2407
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2408
	return $self->_subclassResponsibility();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2409
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2410
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2411
# A place holder to catch rewindData errors if someone ignores
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2412
# the error code.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2413
sub _noChunk	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2414
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2415
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2416
	return ( \undef, _error( "trying to copy chunk when init failed" ));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2417
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2418
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2419
# Basically a no-op so that I can have a consistent interface.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2420
# ( $outputRef, $status) = $self->_copyChunk( \$buffer );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2421
sub _copyChunk	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2422
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2423
	my ( $self, $dataRef ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2424
	return ( $dataRef, AZ_OK );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2425
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2426
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2427
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2428
# ( $outputRef, $status) = $self->_deflateChunk( \$buffer );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2429
sub _deflateChunk	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2430
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2431
	my ( $self, $buffer ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2432
	my ( $out, $status ) = $self->_deflater()->deflate( $buffer );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2433
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2434
	if ( $self->_readDataRemaining() == 0 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2435
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2436
		my $extraOutput;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2437
		( $extraOutput, $status ) = $self->_deflater()->flush();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2438
		$out .= $extraOutput;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2439
		$self->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2440
		return ( \$out, AZ_STREAM_END );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2441
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2442
	elsif ( $status == Z_OK )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2443
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2444
		return ( \$out, AZ_OK );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2445
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2446
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2447
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2448
		$self->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2449
		my $retval = _error( 'deflate error', $status);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2450
		my $dummy = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2451
		return ( \$dummy, $retval );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2452
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2453
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2454
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2455
# ( $outputRef, $status) = $self->_inflateChunk( \$buffer );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2456
sub _inflateChunk	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2457
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2458
	my ( $self, $buffer ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2459
	my ( $out, $status ) = $self->_inflater()->inflate( $buffer );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2460
	my $retval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2461
	$self->endRead() if ( $status != Z_OK );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2462
	if ( $status == Z_OK || $status == Z_STREAM_END )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2463
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2464
		$retval = ( $status == Z_STREAM_END )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2465
			? AZ_STREAM_END : AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2466
		return ( \$out, $retval );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2467
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2468
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2469
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2470
		$retval = _error( 'inflate error', $status);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2471
		my $dummy = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2472
		return ( \$dummy, $retval );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2473
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2474
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2475
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2476
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2477
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2478
=item rewindData()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2479
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2480
Rewind data and set up for reading data streams or writing zip files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2481
Can take options for C<inflateInit()> or C<deflateInit()>,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2482
but this isn't likely to be necessary.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2483
Subclass overrides should call this method.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2484
Returns C<AZ_OK> on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2485
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2486
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2487
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2488
sub rewindData	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2489
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2490
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2491
	my $status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2492
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2493
	# set to trap init errors
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2494
	$self->{'chunkHandler'} = $self->can( '_noChunk' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2495
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2496
	# Work around WinZip defect with 0-length DEFLATED files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2497
	$self->desiredCompressionMethod( COMPRESSION_STORED )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2498
		if $self->uncompressedSize() == 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2499
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2500
	# assume that we're going to read the whole file, and compute the CRC anew.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2501
	$self->{'crc32'} = 0 if ( $self->compressionMethod() == COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2502
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2503
	# These are the only combinations of methods we deal with right now.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2504
	if ( $self->compressionMethod() == COMPRESSION_STORED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2505
			and $self->desiredCompressionMethod() == COMPRESSION_DEFLATED )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2506
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2507
		( $self->{'deflater'}, $status ) = Compress::Zlib::deflateInit(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2508
			'-Level' => $self->desiredCompressionLevel(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2509
			'-WindowBits' => - MAX_WBITS(), # necessary magic
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2510
			@_ );	# pass additional options
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2511
		return _error( 'deflateInit error:', $status ) if $status != Z_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2512
		$self->{'chunkHandler'} = $self->can( '_deflateChunk' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2513
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2514
	elsif ( $self->compressionMethod() == COMPRESSION_DEFLATED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2515
			and $self->desiredCompressionMethod() == COMPRESSION_STORED )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2516
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2517
		( $self->{'inflater'}, $status ) = Compress::Zlib::inflateInit(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2518
			'-WindowBits' => - MAX_WBITS(), # necessary magic
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2519
			@_ );	# pass additional options
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2520
		return _error( 'inflateInit error:', $status ) if $status != Z_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2521
		$self->{'chunkHandler'} = $self->can( '_inflateChunk' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2522
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2523
	elsif ( $self->compressionMethod() == $self->desiredCompressionMethod() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2524
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2525
		$self->{'chunkHandler'} = $self->can( '_copyChunk' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2526
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2527
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2528
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2529
		return _error(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2530
			sprintf( "Unsupported compression combination: read %d, write %d",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2531
				$self->compressionMethod(),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2532
				$self->desiredCompressionMethod() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2533
		 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2534
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2535
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2536
	$self->{'dataEnded'} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2537
	$self->{'readDataRemaining'} = $self->compressedSize();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2538
	$self->{'readOffset'} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2539
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2540
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2541
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2542
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2543
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2544
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2545
=item endRead()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2546
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2547
Reset the read variables and free the inflater or deflater.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2548
Must be called to close files, etc.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2549
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2550
Returns AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2551
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2552
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2553
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2554
sub endRead	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2555
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2556
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2557
	delete $self->{'inflater'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2558
	delete $self->{'deflater'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2559
	$self->{'dataEnded'} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2560
	$self->{'readDataRemaining'} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2561
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2562
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2563
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2564
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2565
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2566
=item readIsDone()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2567
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2568
Return true if the read has run out of data or errored out.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2569
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2570
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2571
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2572
sub readIsDone	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2573
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2574
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2575
	return ( $self->_dataEnded() or ! $self->_readDataRemaining() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2576
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2577
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2578
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2579
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2580
=item contents()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2581
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2582
Return the entire uncompressed member data or undef in scalar context.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2583
When called in array context, returns C<( $string, $status )>; status
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2584
will be AZ_OK on success:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2585
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2586
    my $string = $member->contents();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2587
    # or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2588
    my ( $string, $status ) = $member->contents();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2589
    die "error $status" if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2590
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2591
Can also be used to set the contents of a member (this may change
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2592
the class of the member):
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2593
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2594
    $member->contents( "this is my new contents" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2595
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2596
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2597
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2598
sub contents	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2599
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2600
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2601
	my $newContents = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2602
	if ( defined( $newContents ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2603
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2604
		$self->_become( STRINGMEMBERCLASS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2605
		return $self->contents( $newContents );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2606
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2607
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2608
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2609
		my $oldCompression = 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2610
			$self->desiredCompressionMethod( COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2611
		my $status = $self->rewindData( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2612
		if ( $status != AZ_OK )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2613
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2614
			$self->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2615
			return $status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2616
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2617
		my $retval = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2618
		while ( $status == AZ_OK )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2619
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2620
			my $ref;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2621
			( $ref, $status ) = $self->readChunk( $self->_readDataRemaining() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2622
			# did we get it in one chunk?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2623
			if ( length( $$ref ) == $self->uncompressedSize() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2624
			{ $retval = $$ref }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2625
			else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2626
			{ $retval .= $$ref }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2627
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2628
		$self->desiredCompressionMethod( $oldCompression );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2629
		$self->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2630
		$status = AZ_OK if $status == AZ_STREAM_END;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2631
		$retval = undef if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2632
		return wantarray ? ( $retval, $status ) : $retval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2633
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2634
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2635
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2636
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2637
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2638
=item extractToFileHandle( $fh )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2639
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2640
Extract (and uncompress, if necessary) my contents to the given file handle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2641
Return AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2642
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2643
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2644
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2645
sub extractToFileHandle	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2646
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2647
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2648
	return _error( "encryption unsupported" ) if $self->isEncrypted();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2649
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2650
	_binmode( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2651
	my $oldCompression = $self->desiredCompressionMethod( COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2652
	my $status = $self->rewindData( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2653
	$status = $self->_writeData( $fh ) if $status == AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2654
	$self->desiredCompressionMethod( $oldCompression );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2655
	$self->endRead();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2656
	return $status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2657
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2658
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2659
# write local header and data stream to file handle
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2660
sub _writeToFileHandle	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2661
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2662
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2663
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2664
	my $fhIsSeekable = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2665
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2666
	# Determine if I need to write a data descriptor
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2667
	# I need to do this if I can't refresh the header
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2668
	# and I don't know compressed size or crc32 fields.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2669
	my $headerFieldsUnknown = ( ( $self->uncompressedSize() > 0 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2670
		and ( $self->compressionMethod() == COMPRESSION_STORED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2671
			or $self->desiredCompressionMethod() == COMPRESSION_DEFLATED ) );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2672
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2673
	my $shouldWriteDataDescriptor =
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2674
		( $headerFieldsUnknown and not $fhIsSeekable );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2676
	$self->hasDataDescriptor( 1 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2677
		if ( $shouldWriteDataDescriptor );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2678
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2679
	$self->{'writeOffset'} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2680
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2681
	my $status = $self->rewindData();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2682
	( $status = $self->_writeLocalFileHeader( $fh ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2683
		if $status == AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2684
	( $status = $self->_writeData( $fh ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2685
		if $status == AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2686
	if ( $status == AZ_OK )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2687
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2688
		if ( $self->hasDataDescriptor() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2689
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2690
			$status = $self->_writeDataDescriptor( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2691
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2692
		elsif ( $headerFieldsUnknown )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2693
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2694
			$status = $self->_refreshLocalFileHeader( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2695
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2696
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2697
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2698
	return $status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2699
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2700
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2701
# Copy my (possibly compressed) data to given file handle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2702
# Returns C<AZ_OK> on success
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2703
sub _writeData	# Archive::Zip::Member
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2704
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2705
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2706
	my $writeFh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2708
	return AZ_OK if ( $self->uncompressedSize() == 0 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2709
	my $status;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2710
	my $chunkSize = $Archive::Zip::ChunkSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2711
	while ( $self->_readDataRemaining() > 0 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2712
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2713
		my $outRef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2714
		( $outRef, $status ) = $self->readChunk( $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2715
		return $status if ( $status != AZ_OK and $status != AZ_STREAM_END );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2716
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2717
		$writeFh->write( $$outRef, length( $$outRef ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2718
			or return _ioError( "write error during copy" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2719
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2720
		last if $status == AZ_STREAM_END;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2721
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2722
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2723
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2724
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2725
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2726
# Return true if I depend on the named file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2727
sub _usesFileNamed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2728
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2729
	return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2730
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2731
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2732
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2733
# class Archive::Zip::DirectoryMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2734
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2735
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2736
package Archive::Zip::DirectoryMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2737
use File::Path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2738
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2739
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2740
@ISA = qw ( Archive::Zip::Member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2741
BEGIN { use Archive::Zip qw( :ERROR_CODES :UTILITY_METHODS ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2742
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2743
sub _newNamed	# Archive::Zip::DirectoryMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2744
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2745
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2746
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2747
	my $self = $class->new( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2748
	$self->fileName( $name );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2749
	if ( -d $name )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2750
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2751
		my @stat = stat( _ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2752
		$self->unixFileAttributes( $stat[2] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2753
		$self->setLastModFileDateTimeFromUnix( $stat[9] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2754
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2755
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2756
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2757
		$self->unixFileAttributes( $self->DEFAULT_DIRECTORY_PERMISSIONS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2758
		$self->setLastModFileDateTimeFromUnix( time() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2759
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2760
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2761
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2762
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2763
sub isDirectory	# Archive::Zip::DirectoryMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2764
{ return 1; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2765
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2766
sub extractToFileNamed	# Archive::Zip::DirectoryMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2767
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2768
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2769
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2770
	my $attribs = $self->unixFileAttributes() & 07777;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2771
	mkpath( $name, 0, $attribs );	# croaks on error
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2772
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2773
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2774
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2775
sub fileName	# Archive::Zip::DirectoryMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2776
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2777
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2778
	my $newName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2779
	$newName =~ s{/?$}{/} if defined( $newName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2780
	return $self->SUPER::fileName( $newName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2781
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2782
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2783
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2784
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2785
=head1 Archive::Zip::FileMember methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2786
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2787
The Archive::Zip::FileMember class extends Archive::Zip::Member.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2788
It is the base class for both ZipFileMember and NewFileMember classes.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2789
This class adds an C<externalFileName> and an C<fh> member to keep
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2790
track of the external file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2791
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2792
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2793
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2794
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2795
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2796
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2797
# class Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2798
# Base class for classes that have file handles
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2799
# to external files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2800
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2801
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2802
package Archive::Zip::FileMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2803
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2804
@ISA = qw ( Archive::Zip::Member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2805
BEGIN { use Archive::Zip qw( :UTILITY_METHODS ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2806
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2807
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2808
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2809
=item externalFileName()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2810
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2811
Return my external filename.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2812
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2813
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2814
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2815
sub externalFileName	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2816
{ shift->{'externalFileName'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2817
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2818
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2819
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2820
# Return true if I depend on the named file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2821
sub _usesFileNamed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2822
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2823
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2824
	my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2825
	return $self->externalFileName eq $fileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2826
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2827
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2828
=item fh()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2829
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2830
Return my read file handle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2831
Automatically opens file if necessary.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2832
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2833
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2834
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2835
sub fh	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2836
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2837
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2838
	$self->_openFile() if ! $self->{'fh'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2839
	return $self->{'fh'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2840
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2841
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2842
# opens my file handle from my file name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2843
sub _openFile	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2844
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2845
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2846
	my ( $status, $fh ) = _newFileHandle( $self->externalFileName(), 'r' );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2847
	if ( !$status )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2848
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2849
		_ioError( "Can't open", $self->externalFileName() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2850
		return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2851
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2852
	$self->{'fh'} = $fh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2853
	_binmode( $fh );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2854
	return $fh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2855
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2856
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2857
# Closes my file handle
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2858
sub _closeFile	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2859
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2860
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2861
	$self->{'fh'} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2862
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2863
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2864
# Make sure I close my file handle
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2865
sub endRead	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2866
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2867
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2868
	$self->_closeFile();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2869
	return $self->SUPER::endRead( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2870
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2871
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2872
sub _become	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2873
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2874
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2875
	my $newClass = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2876
	return $self if ref( $self ) eq $newClass;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2877
	delete( $self->{'externalFileName'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2878
	delete( $self->{'fh'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2879
	return $self->SUPER::_become( $newClass );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2880
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2881
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2882
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2883
# class Archive::Zip::NewFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2884
# Used when adding a pre-existing file to an archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2885
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2886
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2887
package Archive::Zip::NewFileMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2888
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2889
@ISA = qw ( Archive::Zip::FileMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2890
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2891
BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :UTILITY_METHODS ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2892
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2893
# Given a file name, set up for eventual writing.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2894
sub _newFromFileNamed	# Archive::Zip::NewFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2895
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2896
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2897
	my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2898
	return undef if ! ( -r $fileName && ( -f _ || -l _ ) );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2899
	my $self = $class->new( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2900
	$self->fileName( $fileName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2901
	$self->{'externalFileName'} = $fileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2902
	$self->{'compressionMethod'} = COMPRESSION_STORED;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2903
	my @stat = stat( _ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2904
	$self->{'compressedSize'} = $self->{'uncompressedSize'} = $stat[7];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2905
	$self->desiredCompressionMethod( ( $self->compressedSize() > 0 )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2906
		? COMPRESSION_DEFLATED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2907
		: COMPRESSION_STORED );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2908
	$self->unixFileAttributes( $stat[2] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2909
	$self->setLastModFileDateTimeFromUnix( $stat[9] );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2910
	$self->isTextFile( -T _ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2911
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2912
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2913
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2914
sub rewindData	# Archive::Zip::NewFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2915
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2916
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2917
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2918
	my $status = $self->SUPER::rewindData( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2919
	return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2920
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2921
	return AZ_IO_ERROR if ! $self->fh();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2922
	$self->fh()->clearerr();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2923
	$self->fh()->seek( 0, IO::Seekable::SEEK_SET )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2924
		or return _ioError( "rewinding", $self->externalFileName() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2925
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2926
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2927
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2928
# Return bytes read. Note that first parameter is a ref to a buffer.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2929
# my $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2930
# my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2931
sub _readRawChunk	# Archive::Zip::NewFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2932
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2933
	my ( $self, $dataRef, $chunkSize ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2934
	return ( 0, AZ_OK ) if ( ! $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2935
	my $bytesRead = $self->fh()->read( $$dataRef, $chunkSize )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2936
		or return ( 0, _ioError( "reading data" ) );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2937
	return ( $bytesRead, AZ_OK );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2938
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2939
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2940
# If I already exist, extraction is a no-op.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2941
sub extractToFileNamed	# Archive::Zip::NewFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2942
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2943
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2944
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2945
	if ( $name eq $self->fileName() and -r $name )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2946
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2947
		return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2948
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2949
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2950
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2951
		return $self->SUPER::extractToFileNamed( $name, @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2952
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2953
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2954
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2955
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2956
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2957
=head1 Archive::Zip::ZipFileMember methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2958
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2959
The Archive::Zip::ZipFileMember class represents members that have
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2960
been read from external zip files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2961
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2962
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2963
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2964
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2965
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2966
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2967
# class Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2968
# This represents a member in an existing zip file on disk.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2969
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2970
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2971
package Archive::Zip::ZipFileMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2972
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2973
@ISA = qw ( Archive::Zip::FileMember );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2974
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2975
BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :PKZIP_CONSTANTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2976
	:UTILITY_METHODS ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2977
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2978
# Create a new Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2979
# given a filename and optional open file handle
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2980
sub _newFromZipFile	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2981
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2982
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2983
	my $fh = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2984
	my $externalFileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2985
	my $self = $class->new(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2986
		'crc32' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2987
		'diskNumberStart' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2988
		'localHeaderRelativeOffset' => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2989
		'dataOffset' =>  0,	# localHeaderRelativeOffset + header length
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2990
		@_
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2991
	 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2992
	$self->{'externalFileName'} = $externalFileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2993
	$self->{'fh'} = $fh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2994
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2995
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2996
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2997
sub isDirectory	# Archive::Zip::FileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2998
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  2999
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3000
	return ( substr( $self->fileName(), -1, 1 ) eq '/'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3001
		and $self->uncompressedSize() == 0 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3002
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3003
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3004
# Because I'm going to delete the file handle, read the local file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3005
# header if the file handle is seekable. If it isn't, I assume that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3006
# I've already read the local header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3007
# Return ( $status, $self )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3008
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3009
sub _become	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3010
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3011
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3012
	my $newClass = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3013
	return $self if ref( $self ) eq $newClass;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3014
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3015
	my $status = AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3016
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3017
	if ( _isSeekable( $self->fh() ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3018
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3019
		my $here = $self->fh()->tell();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3020
		$status = $self->fh()->seek(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3021
			$self->localHeaderRelativeOffset() + SIGNATURE_LENGTH,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3022
			IO::Seekable::SEEK_SET );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3023
		if ( ! $status )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3024
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3025
			$self->fh()->seek( $here );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3026
			_ioError( "seeking to local header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3027
			return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3028
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3029
		$self->_readLocalFileHeader();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3030
		$self->fh()->seek( $here, IO::Seekable::SEEK_SET );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3031
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3032
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3033
	delete( $self->{'diskNumberStart'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3034
	delete( $self->{'localHeaderRelativeOffset'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3035
	delete( $self->{'dataOffset'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3036
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3037
	return $self->SUPER::_become( $newClass );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3038
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3039
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3040
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3041
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3042
=item diskNumberStart()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3043
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3044
Returns the disk number that my local header resides
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3045
in. Had better be 0.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3046
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3047
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3048
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3049
sub diskNumberStart	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3050
{ shift->{'diskNumberStart'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3051
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3052
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3053
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3054
=item localHeaderRelativeOffset()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3055
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3056
Returns the offset into the zip file where my local header is.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3057
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3058
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3059
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3060
sub localHeaderRelativeOffset	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3061
{ shift->{'localHeaderRelativeOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3062
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3063
#--------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3064
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3065
=item dataOffset()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3066
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3067
Returns the offset from the beginning of the zip file to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3068
my data.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3069
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3070
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3071
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3072
sub dataOffset	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3073
{ shift->{'dataOffset'} }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3074
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3075
# Skip local file header, updating only extra field stuff.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3076
# Assumes that fh is positioned before signature.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3077
sub _skipLocalFileHeader	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3078
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3079
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3080
	my $header;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3081
	$self->fh()->read( $header, LOCAL_FILE_HEADER_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3082
		or return _ioError( "reading local file header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3083
	my $fileNameLength;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3084
	my $extraFieldLength;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3085
	(	undef, 	# $self->{'versionNeededToExtract'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3086
		undef,	# $self->{'bitFlag'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3087
		undef,	# $self->{'compressionMethod'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3088
		undef,	# $self->{'lastModFileDateTime'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3089
		undef,	# $crc32,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3090
		undef,	# $compressedSize,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3091
		undef,	# $uncompressedSize,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3092
		$fileNameLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3093
		$extraFieldLength ) = unpack( LOCAL_FILE_HEADER_FORMAT, $header );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3094
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3095
	if ( $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3096
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3097
		$self->fh()->seek( $fileNameLength, IO::Seekable::SEEK_CUR )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3098
			or return _ioError( "skipping local file name" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3099
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3100
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3101
	if ( $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3102
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3103
		$self->fh()->read( $self->{'localExtraField'}, $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3104
			or return _ioError( "reading local extra field" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3105
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3107
	$self->{'dataOffset'} = $self->fh()->tell();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3108
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3109
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3110
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3111
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3112
# Read from a local file header into myself. Returns AZ_OK if successful.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3113
# Assumes that fh is positioned after signature.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3114
# Note that crc32, compressedSize, and uncompressedSize will be 0 if
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3115
# GPBF_HAS_DATA_DESCRIPTOR_MASK is set in the bitFlag.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3116
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3117
sub _readLocalFileHeader	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3118
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3119
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3120
	my $header;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3121
	$self->fh()->read( $header, LOCAL_FILE_HEADER_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3122
		or return _ioError( "reading local file header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3123
	my $fileNameLength;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3124
	my $crc32;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3125
	my $compressedSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3126
	my $uncompressedSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3127
	my $extraFieldLength;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3128
	(	$self->{'versionNeededToExtract'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3129
		$self->{'bitFlag'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3130
		$self->{'compressionMethod'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3131
		$self->{'lastModFileDateTime'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3132
		$crc32,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3133
		$compressedSize,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3134
		$uncompressedSize,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3135
		$fileNameLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3136
		$extraFieldLength ) = unpack( LOCAL_FILE_HEADER_FORMAT, $header );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3137
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3138
	if ( $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3139
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3140
		my $fileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3141
		$self->fh()->read( $fileName, $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3142
			or return _ioError( "reading local file name" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3143
		$self->fileName( $fileName );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3144
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3145
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3146
	if ( $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3147
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3148
		$self->fh()->read( $self->{'localExtraField'}, $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3149
			or return _ioError( "reading local extra field" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3150
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3151
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3152
	$self->{'dataOffset'} = $self->fh()->tell();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3154
	# Don't trash these fields from the CD if we already have them.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3155
	if ( not $self->hasDataDescriptor() )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3156
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3157
		$self->{'crc32'} = $crc32;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3158
		$self->{'compressedSize'} = $compressedSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3159
		$self->{'uncompressedSize'} = $uncompressedSize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3160
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3162
	# We ignore data descriptors (we don't read them,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3163
	# and we compute elsewhere whether we need to write them ).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3164
	# And, we have the necessary data from the CD header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3165
	# So mark this entry as not having a data descriptor.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3166
	$self->hasDataDescriptor( 0 );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3167
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3168
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3169
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3171
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3172
# Read a Central Directory header. Return AZ_OK on success.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3173
# Assumes that fh is positioned right after the signature.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3174
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3175
sub _readCentralDirectoryFileHeader	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3176
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3177
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3178
	my $fh = $self->fh();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3179
	my $header = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3180
	$fh->read( $header, CENTRAL_DIRECTORY_FILE_HEADER_LENGTH )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3181
		or return _ioError( "reading central dir header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3182
	my ( $fileNameLength, $extraFieldLength, $fileCommentLength );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3183
	(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3184
		$self->{'versionMadeBy'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3185
		$self->{'fileAttributeFormat'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3186
		$self->{'versionNeededToExtract'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3187
		$self->{'bitFlag'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3188
		$self->{'compressionMethod'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3189
		$self->{'lastModFileDateTime'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3190
		$self->{'crc32'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3191
		$self->{'compressedSize'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3192
		$self->{'uncompressedSize'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3193
		$fileNameLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3194
		$extraFieldLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3195
		$fileCommentLength,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3196
		$self->{'diskNumberStart'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3197
		$self->{'internalFileAttributes'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3198
		$self->{'externalFileAttributes'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3199
		$self->{'localHeaderRelativeOffset'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3200
	 ) = unpack( CENTRAL_DIRECTORY_FILE_HEADER_FORMAT, $header );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3202
	if ( $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3203
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3204
		$fh->read( $self->{'fileName'}, $fileNameLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3205
			or return _ioError( "reading central dir filename" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3206
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3207
	if ( $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3208
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3209
		$fh->read( $self->{'cdExtraField'}, $extraFieldLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3210
			or return _ioError( "reading central dir extra field" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3211
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3212
	if ( $fileCommentLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3213
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3214
		$fh->read( $self->{'fileComment'}, $fileCommentLength )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3215
			or return _ioError( "reading central dir file comment" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3216
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3218
	$self->desiredCompressionMethod( $self->compressionMethod() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3219
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3220
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3221
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3222
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3223
sub rewindData	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3224
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3225
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3226
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3227
	my $status = $self->SUPER::rewindData( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3228
	return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3230
	return AZ_IO_ERROR if ! $self->fh();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3231
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3232
	$self->fh()->clearerr();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3234
	# Seek to local file header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3235
	# The only reason that I'm doing this this way is that the extraField
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3236
	# length seems to be different between the CD header and the LF header.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3237
	$self->fh()->seek( $self->localHeaderRelativeOffset() + SIGNATURE_LENGTH,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3238
		IO::Seekable::SEEK_SET )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3239
			or return _ioError( "seeking to local header" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3240
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3241
	# skip local file header
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3242
	$status = $self->_skipLocalFileHeader();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3243
	return $status if $status != AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3244
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3245
	# Seek to beginning of file data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3246
	$self->fh()->seek( $self->dataOffset(), IO::Seekable::SEEK_SET )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3247
		or return _ioError( "seeking to beginning of file data" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3249
	return AZ_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3250
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3251
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3252
# Return bytes read. Note that first parameter is a ref to a buffer.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3253
# my $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3254
# my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3255
sub _readRawChunk	# Archive::Zip::ZipFileMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3256
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3257
	my ( $self, $dataRef, $chunkSize ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3258
	return ( 0, AZ_OK )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3259
		if ( ! $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3260
	my $bytesRead = $self->fh()->read( $$dataRef, $chunkSize )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3261
		or return ( 0, _ioError( "reading data" ) );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3262
	return ( $bytesRead, AZ_OK );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3263
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3264
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3265
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3266
# class Archive::Zip::StringMember ( concrete )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3267
# A Zip member whose data lives in a string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3268
# ----------------------------------------------------------------------
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3269
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3270
package Archive::Zip::StringMember;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3271
use vars qw( @ISA );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3272
@ISA = qw ( Archive::Zip::Member );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3273
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3274
BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES ) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3275
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3276
# Create a new string member. Default is COMPRESSION_STORED.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3277
# Can take a ref to a string as well.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3278
sub _newFromString	# Archive::Zip::StringMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3279
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3280
	my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3281
	my $string = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3282
	my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3283
	my $self = $class->new( @_ );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3284
	$self->contents( $string );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3285
	$self->fileName( $name ) if defined( $name );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3286
	# Set the file date to now
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3287
	$self->setLastModFileDateTimeFromUnix( time() );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3288
	$self->unixFileAttributes( $self->DEFAULT_FILE_PERMISSIONS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3289
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3290
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3291
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3292
sub _become	# Archive::Zip::StringMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3293
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3294
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3295
	my $newClass = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3296
	return $self if ref( $self ) eq $newClass;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3297
	delete( $self->{'contents'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3298
	return $self->SUPER::_become( $newClass );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3299
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3301
# Get or set my contents. Note that we do not call the superclass
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3302
# version of this, because it calls us.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3303
sub contents    # Archive::Zip::StringMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3304
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3305
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3306
	my $string = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3307
	if ( defined( $string ) )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3308
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3309
		$self->{'contents'} = ( ref( $string ) eq 'SCALAR' )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3310
			? $$string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3311
			: $string;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3312
		$self->{'uncompressedSize'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3313
			= $self->{'compressedSize'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3314
			= length( $self->{'contents'} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3315
		$self->{'compressionMethod'} = COMPRESSION_STORED;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3316
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3317
	return $self->{'contents'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3318
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3319
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3320
# Return bytes read. Note that first parameter is a ref to a buffer.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3321
# my $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3322
# my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3323
sub _readRawChunk	# Archive::Zip::StringMember
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3324
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3325
	my ( $self, $dataRef, $chunkSize ) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3326
	$$dataRef = substr( $self->contents(), $self->_readOffset(), $chunkSize );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3327
	return ( length( $$dataRef ), AZ_OK );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3328
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3329
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3330
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3331
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3332
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3333
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3334
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3335
=head1 AUTHOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3336
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3337
Ned Konz, perl@bike-nomad.com
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3339
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3340
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3341
Copyright (c) 2000 Ned Konz. All rights reserved.  This program is free
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3342
software; you can redistribute it and/or modify it under the same terms
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3343
as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3344
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3345
=head1 SEE ALSO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3346
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3347
L<Compress::Zlib>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3348
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3349
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3350
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  3351
# vim: ts=4 sw=4 columns=80