[Slim-Checkins] r11021 - in /trunk/server: ./ CPAN/ CPAN/Archive/
CPAN/Archive/Zip/
CPAN/PAR/ HTML/EN/ HTML/EN/html/ HTML/EN/html/images/
HTML/EN/html/scriptaculous/ HTML/EN/settings/server/ Plugins/CLI/
Plugins/DateTime/ Plugins/DigitalInput/
Plugins/DigitalInput/HTML/EN/plugins/DigitalInput/ Plugins/Health/
Plugins/LMA/ Plugins/Live365/ Plugins/MoodLogic/ Plugins/MusicMagic/
Plugins/Picks/ Plugins/Podcast/ Plugins/PreventStandby/ Plugins/RPC/
Plugins/RS232/ Plugins/RSSNews/ Plugins/RadioIO/ Plugins/RadioTime/
Plugins/RandomPlay/ Plugins/RandomPlay/HTML/EN/plugins/RandomPlay/
Plugins/Rescan/ Plugins/Rhapsody/ Plugins/SavePlaylist/
Plugins/ShoutcastBrowser/ Plugins/SlimTris/ Plugins/Snow/ Plugins/TT/
Plugins/Visualizer/ Plugins/iTunes/ Plugins/xPL/ Slim/Buttons/
Slim/Control/ Slim/Display/Lib/ Slim/Music/ Slim/Player/ Slim/Plugin/
Slim/Utils/ Slim/Web/ Slim/Web/Pages/ Slim/Web/Settings/Player/
Slim/Web/Settings/Server/
dsully at svn.slimdevices.com
dsully at svn.slimdevices.com
Thu Dec 21 14:28:39 PST 2006
Author: dsully
Date: Thu Dec 21 14:28:39 2006
New Revision: 11021
URL: http://svn.slimdevices.com?rev=11021&view=rev
Log:
Bug: 4112
Description: First checkin of new Plugin Infrastructure.
Lots of things aren't working yet. See TODO in Slim/Utils/PluginManager.pm
Added:
trunk/server/CPAN/Archive/
trunk/server/CPAN/Archive/Zip/
trunk/server/CPAN/Archive/Zip.pm (with props)
trunk/server/CPAN/Archive/Zip/Archive.pm (with props)
trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm (with props)
trunk/server/CPAN/Archive/Zip/DirectoryMember.pm (with props)
trunk/server/CPAN/Archive/Zip/FAQ.pod
trunk/server/CPAN/Archive/Zip/FileMember.pm (with props)
trunk/server/CPAN/Archive/Zip/Member.pm (with props)
trunk/server/CPAN/Archive/Zip/MemberRead.pm (with props)
trunk/server/CPAN/Archive/Zip/MockFileHandle.pm (with props)
trunk/server/CPAN/Archive/Zip/NewFileMember.pm (with props)
trunk/server/CPAN/Archive/Zip/StringMember.pm (with props)
trunk/server/CPAN/Archive/Zip/Tree.pm (with props)
trunk/server/CPAN/Archive/Zip/ZipFileMember.pm (with props)
trunk/server/CPAN/PAR/
trunk/server/CPAN/PAR.pm (with props)
trunk/server/CPAN/PAR/Dist.pm (with props)
trunk/server/CPAN/PAR/Heavy.pm (with props)
trunk/server/HTML/EN/html/images/extensionItem.png (with props)
trunk/server/HTML/EN/html/prototype-1.5.js (with props)
trunk/server/HTML/EN/html/scriptaculous/
trunk/server/HTML/EN/html/scriptaculous/builder.js (with props)
trunk/server/HTML/EN/html/scriptaculous/controls.js (with props)
trunk/server/HTML/EN/html/scriptaculous/dragdrop.js (with props)
trunk/server/HTML/EN/html/scriptaculous/effects.js (with props)
trunk/server/HTML/EN/html/scriptaculous/scriptaculous.js (with props)
trunk/server/HTML/EN/html/scriptaculous/slider.js (with props)
trunk/server/HTML/EN/html/scriptaculous/unittest.js (with props)
trunk/server/HTML/EN/settings/server/plugins.html (with props)
trunk/server/Plugins/CLI/install.xml (with props)
trunk/server/Plugins/DateTime/install.xml (with props)
trunk/server/Plugins/DigitalInput/HTML/EN/plugins/DigitalInput/list.html
- copied, changed from r10921, trunk/server/Plugins/DigitalInput/HTML/EN/plugins/DigitalInput/digitalinput_list.html
trunk/server/Plugins/DigitalInput/install.xml (with props)
trunk/server/Plugins/Health/install.xml (with props)
trunk/server/Plugins/LMA/install.xml (with props)
trunk/server/Plugins/Live365/install.xml (with props)
trunk/server/Plugins/MusicMagic/install.xml (with props)
trunk/server/Plugins/Picks/install.xml (with props)
trunk/server/Plugins/Podcast/install.xml (with props)
trunk/server/Plugins/PreventStandby/install.xml (with props)
trunk/server/Plugins/RPC/install.xml (with props)
trunk/server/Plugins/RS232/install.xml (with props)
trunk/server/Plugins/RSSNews/install.xml (with props)
trunk/server/Plugins/RadioIO/install.xml (with props)
trunk/server/Plugins/RadioTime/install.xml (with props)
trunk/server/Plugins/RandomPlay/HTML/EN/plugins/RandomPlay/list.html
- copied, changed from r9010, trunk/server/Plugins/RandomPlay/HTML/EN/plugins/RandomPlay/randomplay_list.html
trunk/server/Plugins/RandomPlay/install.xml (with props)
trunk/server/Plugins/Rescan/install.xml (with props)
trunk/server/Plugins/Rhapsody/install.xml (with props)
trunk/server/Plugins/SavePlaylist/install.xml (with props)
trunk/server/Plugins/ShoutcastBrowser/install.xml (with props)
trunk/server/Plugins/SlimTris/install.xml (with props)
trunk/server/Plugins/Snow/install.xml (with props)
trunk/server/Plugins/TT/README
trunk/server/Plugins/Visualizer/install.xml (with props)
trunk/server/Plugins/iTunes/install.xml (with props)
trunk/server/Plugins/xPL/install.xml (with props)
trunk/server/Slim/Plugin/
trunk/server/Slim/Plugin/Base.pm (with props)
trunk/server/Slim/Web/Settings/Server/Plugins.pm (with props)
Removed:
trunk/server/HTML/EN/setup_group.html
trunk/server/HTML/EN/setup_input_array_add.html
trunk/server/HTML/EN/setup_input_array_chk.html
trunk/server/HTML/EN/setup_input_array_sel.html
trunk/server/HTML/EN/setup_input_array_txt.html
trunk/server/HTML/EN/setup_input_array_udr.html
trunk/server/HTML/EN/setup_input_chk.html
trunk/server/HTML/EN/setup_input_passwd.html
trunk/server/HTML/EN/setup_input_radio.html
trunk/server/HTML/EN/setup_input_sel.html
trunk/server/HTML/EN/setup_input_submit.html
trunk/server/HTML/EN/setup_input_txt.html
trunk/server/HTML/EN/setup_pref.html
trunk/server/HTML/EN/setup_radio_option.html
trunk/server/HTML/EN/setup_titleformat.html
trunk/server/HTML/EN/setup_titleformat_adv.html
trunk/server/Plugins/DigitalInput/HTML/EN/plugins/DigitalInput/digitalinput_list.html
trunk/server/Plugins/RandomPlay/HTML/EN/plugins/RandomPlay/randomplay_list.html
Modified:
trunk/server/Plugins/DateTime/Plugin.pm
trunk/server/Plugins/DigitalInput/Plugin.pm
trunk/server/Plugins/Health/Plugin.pm
trunk/server/Plugins/LMA/Plugin.pm
trunk/server/Plugins/Live365/Plugin.pm
trunk/server/Plugins/MoodLogic/Plugin.pm
trunk/server/Plugins/MusicMagic/Plugin.pm
trunk/server/Plugins/Picks/Plugin.pm
trunk/server/Plugins/Podcast/Plugin.pm
trunk/server/Plugins/PreventStandby/Plugin.pm
trunk/server/Plugins/RPC/Plugin.pm
trunk/server/Plugins/RS232/Plugin.pm
trunk/server/Plugins/RSSNews/Plugin.pm
trunk/server/Plugins/RadioIO/Plugin.pm
trunk/server/Plugins/RadioTime/Plugin.pm
trunk/server/Plugins/RandomPlay/Plugin.pm
trunk/server/Plugins/Rescan/Plugin.pm
trunk/server/Plugins/Rhapsody/Plugin.pm
trunk/server/Plugins/SavePlaylist/Plugin.pm
trunk/server/Plugins/ShoutcastBrowser/Plugin.pm
trunk/server/Plugins/SlimTris/Plugin.pm
trunk/server/Plugins/Snow/Plugin.pm
trunk/server/Plugins/Visualizer/Plugin.pm
trunk/server/Slim/Buttons/AlarmClock.pm
trunk/server/Slim/Buttons/Common.pm
trunk/server/Slim/Buttons/Home.pm
trunk/server/Slim/Buttons/Information.pm
trunk/server/Slim/Control/Request.pm
trunk/server/Slim/Display/Lib/Fonts.pm
trunk/server/Slim/Music/Import.pm
trunk/server/Slim/Music/Info.pm
trunk/server/Slim/Player/Player.pm
trunk/server/Slim/Player/TranscodingHelper.pm
trunk/server/Slim/Player/Transporter.pm
trunk/server/Slim/Utils/OSDetect.pm
trunk/server/Slim/Utils/PluginManager.pm
trunk/server/Slim/Utils/Prefs.pm
trunk/server/Slim/Utils/Strings.pm
trunk/server/Slim/Web/Pages/Home.pm
trunk/server/Slim/Web/Settings.pm
trunk/server/Slim/Web/Settings/Player/Menu.pm
trunk/server/Slim/Web/Settings/Server/Basic.pm
trunk/server/Slim/Web/XMLBrowser.pm
trunk/server/scanner.pl
trunk/server/slimserver.pl
Added: trunk/server/CPAN/Archive/Zip.pm
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip.pm?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip.pm (added)
+++ trunk/server/CPAN/Archive/Zip.pm Thu Dec 21 14:28:39 2006
@@ -1,0 +1,2042 @@
+package Archive::Zip;
+
+# Copyright 2000 - 2002 Ned Konz. All rights reserved. This program is free
+# software; you can redistribute it and/or modify it under the same terms as
+# Perl itself.
+
+# ----------------------------------------------------------------------
+# class Archive::Zip
+# Note that the package Archive::Zip exists only for exporting and
+# sharing constants. Everything else is in another package
+# in this file.
+# Creation of a new Archive::Zip object actually creates a new object
+# of class Archive::Zip::Archive.
+# ----------------------------------------------------------------------
+
+BEGIN {
+ require 5.003_96;
+}
+use strict;
+use UNIVERSAL ();
+use Carp ();
+use IO::File ();
+use IO::Seekable ();
+use Compress::Zlib ();
+use File::Spec ();
+use File::Temp ();
+
+use vars qw( $VERSION @ISA );
+BEGIN {
+ $VERSION = '1.18';
+ $VERSION = eval $VERSION;
+
+ require Exporter;
+ @ISA = qw( Exporter );
+}
+
+use vars qw( $ChunkSize $ErrorHandler );
+
+# This is the size we'll try to read, write, and (de)compress.
+# You could set it to something different if you had lots of memory
+# and needed more speed.
+$ChunkSize = 32768;
+
+$ErrorHandler = \&Carp::carp;
+
+# BEGIN block is necessary here so that other modules can use the constants.
+use vars qw( @EXPORT_OK %EXPORT_TAGS );
+BEGIN {
+ @EXPORT_OK = ('computeCRC32');
+ %EXPORT_TAGS = (
+ CONSTANTS => [ qw(
+ FA_MSDOS
+ FA_UNIX
+ GPBF_ENCRYPTED_MASK
+ GPBF_DEFLATING_COMPRESSION_MASK
+ GPBF_HAS_DATA_DESCRIPTOR_MASK
+ COMPRESSION_STORED
+ COMPRESSION_DEFLATED
+ COMPRESSION_LEVEL_NONE
+ COMPRESSION_LEVEL_DEFAULT
+ COMPRESSION_LEVEL_FASTEST
+ COMPRESSION_LEVEL_BEST_COMPRESSION
+ IFA_TEXT_FILE_MASK
+ IFA_TEXT_FILE
+ IFA_BINARY_FILE
+ ) ],
+
+ MISC_CONSTANTS => [ qw(
+ FA_AMIGA
+ FA_VAX_VMS
+ FA_VM_CMS
+ FA_ATARI_ST
+ FA_OS2_HPFS
+ FA_MACINTOSH
+ FA_Z_SYSTEM
+ FA_CPM
+ FA_TOPS20
+ FA_WINDOWS_NTFS
+ FA_QDOS
+ FA_ACORN
+ FA_VFAT
+ FA_MVS
+ FA_BEOS
+ FA_TANDEM
+ FA_THEOS
+ GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK
+ GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK
+ GPBF_IS_COMPRESSED_PATCHED_DATA_MASK
+ COMPRESSION_SHRUNK
+ DEFLATING_COMPRESSION_NORMAL
+ DEFLATING_COMPRESSION_MAXIMUM
+ DEFLATING_COMPRESSION_FAST
+ DEFLATING_COMPRESSION_SUPER_FAST
+ COMPRESSION_REDUCED_1
+ COMPRESSION_REDUCED_2
+ COMPRESSION_REDUCED_3
+ COMPRESSION_REDUCED_4
+ COMPRESSION_IMPLODED
+ COMPRESSION_TOKENIZED
+ COMPRESSION_DEFLATED_ENHANCED
+ COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED
+ ) ],
+
+ ERROR_CODES => [ qw(
+ AZ_OK
+ AZ_STREAM_END
+ AZ_ERROR
+ AZ_FORMAT_ERROR
+ AZ_IO_ERROR
+ ) ],
+
+ # For Internal Use Only
+ PKZIP_CONSTANTS => [ qw(
+ SIGNATURE_FORMAT
+ SIGNATURE_LENGTH
+ LOCAL_FILE_HEADER_SIGNATURE
+ LOCAL_FILE_HEADER_FORMAT
+ LOCAL_FILE_HEADER_LENGTH
+ CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE
+ DATA_DESCRIPTOR_FORMAT
+ DATA_DESCRIPTOR_LENGTH
+ DATA_DESCRIPTOR_SIGNATURE
+ DATA_DESCRIPTOR_FORMAT_NO_SIG
+ DATA_DESCRIPTOR_LENGTH_NO_SIG
+ CENTRAL_DIRECTORY_FILE_HEADER_FORMAT
+ CENTRAL_DIRECTORY_FILE_HEADER_LENGTH
+ END_OF_CENTRAL_DIRECTORY_SIGNATURE
+ END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING
+ END_OF_CENTRAL_DIRECTORY_FORMAT
+ END_OF_CENTRAL_DIRECTORY_LENGTH
+ ) ],
+
+ # For Internal Use Only
+ UTILITY_METHODS => [ qw(
+ _error
+ _printError
+ _ioError
+ _formatError
+ _subclassResponsibility
+ _binmode
+ _isSeekable
+ _newFileHandle
+ _readSignature
+ _asZipDirName
+ ) ],
+ );
+
+ # Add all the constant names and error code names to @EXPORT_OK
+ Exporter::export_ok_tags( qw(
+ CONSTANTS
+ ERROR_CODES
+ PKZIP_CONSTANTS
+ UTILITY_METHODS
+ MISC_CONSTANTS
+ ) );
+
+}
+
+# Error codes
+use constant AZ_OK => 0;
+use constant AZ_STREAM_END => 1;
+use constant AZ_ERROR => 2;
+use constant AZ_FORMAT_ERROR => 3;
+use constant AZ_IO_ERROR => 4;
+
+# File types
+# Values of Archive::Zip::Member->fileAttributeFormat()
+
+use constant FA_MSDOS => 0;
+use constant FA_AMIGA => 1;
+use constant FA_VAX_VMS => 2;
+use constant FA_UNIX => 3;
+use constant FA_VM_CMS => 4;
+use constant FA_ATARI_ST => 5;
+use constant FA_OS2_HPFS => 6;
+use constant FA_MACINTOSH => 7;
+use constant FA_Z_SYSTEM => 8;
+use constant FA_CPM => 9;
+use constant FA_TOPS20 => 10;
+use constant FA_WINDOWS_NTFS => 11;
+use constant FA_QDOS => 12;
+use constant FA_ACORN => 13;
+use constant FA_VFAT => 14;
+use constant FA_MVS => 15;
+use constant FA_BEOS => 16;
+use constant FA_TANDEM => 17;
+use constant FA_THEOS => 18;
+
+# general-purpose bit flag masks
+# Found in Archive::Zip::Member->bitFlag()
+
+use constant GPBF_ENCRYPTED_MASK => 1 << 0;
+use constant GPBF_DEFLATING_COMPRESSION_MASK => 3 << 1;
+use constant GPBF_HAS_DATA_DESCRIPTOR_MASK => 1 << 3;
+
+# deflating compression types, if compressionMethod == COMPRESSION_DEFLATED
+# ( Archive::Zip::Member->bitFlag() & GPBF_DEFLATING_COMPRESSION_MASK )
+
+use constant DEFLATING_COMPRESSION_NORMAL => 0 << 1;
+use constant DEFLATING_COMPRESSION_MAXIMUM => 1 << 1;
+use constant DEFLATING_COMPRESSION_FAST => 2 << 1;
+use constant DEFLATING_COMPRESSION_SUPER_FAST => 3 << 1;
+
+# compression method
+
+# these two are the only ones supported in this module
+use constant COMPRESSION_STORED => 0; # file is stored (no compression)
+use constant COMPRESSION_DEFLATED => 8; # file is Deflated
+use constant COMPRESSION_LEVEL_NONE => 0;
+use constant COMPRESSION_LEVEL_DEFAULT => -1;
+use constant COMPRESSION_LEVEL_FASTEST => 1;
+use constant COMPRESSION_LEVEL_BEST_COMPRESSION => 9;
+
+# internal file attribute bits
+# Found in Archive::Zip::Member::internalFileAttributes()
+
+use constant IFA_TEXT_FILE_MASK => 1;
+use constant IFA_TEXT_FILE => 1;
+use constant IFA_BINARY_FILE => 0;
+
+# PKZIP file format miscellaneous constants (for internal use only)
+use constant SIGNATURE_FORMAT => "V";
+use constant SIGNATURE_LENGTH => 4;
+
+# these lengths are without the signature.
+use constant LOCAL_FILE_HEADER_SIGNATURE => 0x04034b50;
+use constant LOCAL_FILE_HEADER_FORMAT => "v3 V4 v2";
+use constant LOCAL_FILE_HEADER_LENGTH => 26;
+
+# PKZIP docs don't mention the signature, but Info-Zip writes it.
+use constant DATA_DESCRIPTOR_SIGNATURE => 0x08074b50;
+use constant DATA_DESCRIPTOR_FORMAT => "V3";
+use constant DATA_DESCRIPTOR_LENGTH => 12;
+
+# but the signature is apparently optional.
+use constant DATA_DESCRIPTOR_FORMAT_NO_SIG => "V2";
+use constant DATA_DESCRIPTOR_LENGTH_NO_SIG => 8;
+
+use constant CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE => 0x02014b50;
+use constant CENTRAL_DIRECTORY_FILE_HEADER_FORMAT => "C2 v3 V4 v5 V2";
+use constant CENTRAL_DIRECTORY_FILE_HEADER_LENGTH => 42;
+
+use constant END_OF_CENTRAL_DIRECTORY_SIGNATURE => 0x06054b50;
+use constant END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING =>
+ pack( "V", END_OF_CENTRAL_DIRECTORY_SIGNATURE );
+use constant END_OF_CENTRAL_DIRECTORY_FORMAT => "v4 V2 v";
+use constant END_OF_CENTRAL_DIRECTORY_LENGTH => 18;
+
+use constant GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK => 1 << 1;
+use constant GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK => 1 << 2;
+use constant GPBF_IS_COMPRESSED_PATCHED_DATA_MASK => 1 << 5;
+
+# the rest of these are not supported in this module
+use constant COMPRESSION_SHRUNK => 1; # file is Shrunk
+use constant COMPRESSION_REDUCED_1 => 2; # file is Reduced CF=1
+use constant COMPRESSION_REDUCED_2 => 3; # file is Reduced CF=2
+use constant COMPRESSION_REDUCED_3 => 4; # file is Reduced CF=3
+use constant COMPRESSION_REDUCED_4 => 5; # file is Reduced CF=4
+use constant COMPRESSION_IMPLODED => 6; # file is Imploded
+use constant COMPRESSION_TOKENIZED => 7; # reserved for Tokenizing compr.
+use constant COMPRESSION_DEFLATED_ENHANCED => 9; # reserved for enh. Deflating
+use constant COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED => 10;
+
+# Load the various required classes
+require Archive::Zip::Archive;
+require Archive::Zip::Member;
+require Archive::Zip::FileMember;
+require Archive::Zip::DirectoryMember;
+require Archive::Zip::ZipFileMember;
+require Archive::Zip::NewFileMember;
+require Archive::Zip::StringMember;
+
+use constant ZIPARCHIVECLASS => 'Archive::Zip::Archive';
+use constant ZIPMEMBERCLASS => 'Archive::Zip::Member';
+
+sub new
+{
+ my $class = shift;
+ return $class->ZIPARCHIVECLASS->new(@_);
+}
+
+sub computeCRC32
+{
+ my $data = shift;
+ $data = shift if ref($data); # allow calling as an obj method
+ my $crc = shift;
+ return Compress::Zlib::crc32( $data, $crc );
+}
+
+# Report or change chunk size used for reading and writing.
+# Also sets Zlib's default buffer size (eventually).
+sub setChunkSize
+{
+ my $chunkSize = shift;
+ $chunkSize = shift if ref($chunkSize); # object method on zip?
+ my $oldChunkSize = $Archive::Zip::ChunkSize;
+ $Archive::Zip::ChunkSize = $chunkSize if ($chunkSize);
+ return $oldChunkSize;
+}
+
+sub chunkSize
+{
+ return $Archive::Zip::ChunkSize;
+}
+
+sub setErrorHandler (&)
+{
+ my $errorHandler = shift;
+ $errorHandler = \&Carp::carp unless defined($errorHandler);
+ my $oldErrorHandler = $Archive::Zip::ErrorHandler;
+ $Archive::Zip::ErrorHandler = $errorHandler;
+ return $oldErrorHandler;
+}
+
+# ----------------------------------------------------------------------
+# Private utility functions (not methods).
+# ----------------------------------------------------------------------
+
+sub _printError
+{
+ my $string = join ( ' ', @_, "\n" );
+ my $oldCarpLevel = $Carp::CarpLevel;
+ $Carp::CarpLevel += 2;
+ &{$ErrorHandler} ($string);
+ $Carp::CarpLevel = $oldCarpLevel;
+}
+
+# This is called on format errors.
+sub _formatError
+{
+ shift if ref( $_[0] );
+ _printError( 'format error:', @_ );
+ return AZ_FORMAT_ERROR;
+}
+
+# This is called on IO errors.
+sub _ioError
+{
+ shift if ref( $_[0] );
+ _printError( 'IO error:', @_, ':', $! );
+ return AZ_IO_ERROR;
+}
+
+# This is called on generic errors.
+sub _error
+{
+ shift if ref( $_[0] );
+ _printError( 'error:', @_ );
+ return AZ_ERROR;
+}
+
+# Called when a subclass should have implemented
+# something but didn't
+sub _subclassResponsibility
+{
+ Carp::croak("subclass Responsibility\n");
+}
+
+# Try to set the given file handle or object into binary mode.
+sub _binmode
+{
+ my $fh = shift;
+ return UNIVERSAL::can( $fh, 'binmode' ) ? $fh->binmode() : binmode($fh);
+}
+
+# Attempt to guess whether file handle is seekable.
+# Because of problems with Windoze, this only returns true when
+# the file handle is a real file.
+sub _isSeekable
+{
+ my $fh = shift;
+ if ( UNIVERSAL::isa($fh, 'IO::Scalar') ) {
+ return 0;
+ }
+ if ( UNIVERSAL::isa($fh, 'IO::String') ) {
+ return 1;
+ }
+ if ( UNIVERSAL::isa($fh, 'IO::Seekable') ) {
+ # Unfortunately, some things like FileHandle objects
+ # return true for Seekable, but AREN'T!!!!!
+ if ( UNIVERSAL::isa($fh, 'FileHandle') ) {
+ return 0;
+ }
+ return 1;
+ }
+ if ( UNIVERSAL::can($fh, 'stat') ) {
+ return -f $fh;
+ }
+ return (
+ UNIVERSAL::can($fh, 'seek') and UNIVERSAL::can($fh, 'tell')
+ ) ? 1 : 0;
+}
+
+# Return an opened IO::Handle
+# my ( $status, fh ) = _newFileHandle( 'fileName', 'w' );
+# Can take a filename, file handle, or ref to GLOB
+# Or, if given something that is a ref but not an IO::Handle,
+# passes back the same thing.
+sub _newFileHandle
+{
+ my $fd = shift;
+ my $status = 1;
+ my $handle;
+
+ if ( ref($fd) )
+ {
+ if ( UNIVERSAL::isa( $fd, 'IO::Scalar' )
+ or UNIVERSAL::isa( $fd, 'IO::String' ) )
+ {
+ $handle = $fd;
+ }
+ elsif ( UNIVERSAL::isa( $fd, 'IO::Handle' )
+ or UNIVERSAL::isa( $fd, 'GLOB' ) )
+ {
+ $handle = IO::File->new();
+ $status = $handle->fdopen( $fd, @_ );
+ }
+ else
+ {
+ $handle = $fd;
+ }
+ }
+ else
+ {
+ $handle = IO::File->new();
+ $status = $handle->open( $fd, @_ );
+ }
+
+ return ( $status, $handle );
+}
+
+# Returns next signature from given file handle, leaves
+# file handle positioned afterwards.
+# In list context, returns ($status, $signature)
+# ( $status, $signature) = _readSignature( $fh, $fileName );
+
+sub _readSignature
+{
+ my $fh = shift;
+ my $fileName = shift;
+ my $expectedSignature = shift; # optional
+
+ my $signatureData;
+ my $bytesRead = $fh->read( $signatureData, SIGNATURE_LENGTH );
+ return _ioError("reading header signature")
+ if $bytesRead != SIGNATURE_LENGTH;
+ my $signature = unpack( SIGNATURE_FORMAT, $signatureData );
+ my $status = AZ_OK;
+
+ # compare with expected signature, if any, or any known signature.
+ if ( ( defined($expectedSignature) && $signature != $expectedSignature )
+ || ( !defined($expectedSignature)
+ && $signature != CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE
+ && $signature != LOCAL_FILE_HEADER_SIGNATURE
+ && $signature != END_OF_CENTRAL_DIRECTORY_SIGNATURE
+ && $signature != DATA_DESCRIPTOR_SIGNATURE ) )
+ {
+ my $errmsg = sprintf( "bad signature: 0x%08x", $signature );
+ if ( _isSeekable($fh) )
+ {
+ $errmsg .=
+ sprintf( " at offset %d", $fh->tell() - SIGNATURE_LENGTH );
+ }
+
+ $status = _formatError("$errmsg in file $fileName");
+ }
+
+ return ( $status, $signature );
+}
+
+# Utility method to make and open a temp file.
+# Will create $temp_dir if it doesn't exist.
+# Returns file handle and name:
+#
+# my ($fh, $name) = Archive::Zip::tempFile();
+# my ($fh, $name) = Archive::Zip::tempFile('mytempdir');
+#
+
+sub tempFile
+{
+ my $dir = shift;
+ my ( $fh, $filename ) = File::Temp::tempfile(
+ SUFFIX => '.zip',
+ UNLINK => 0, # we will delete it!
+ $dir ? ( DIR => $dir ) : ()
+ );
+ return ( undef, undef ) unless $fh;
+ my ( $status, $newfh ) = _newFileHandle( $fh, 'w+' );
+ return ( $newfh, $filename );
+}
+
+# Return the normalized directory name as used in a zip file (path
+# separators become slashes, etc.).
+# Will translate internal slashes in path components (i.e. on Macs) to
+# underscores. Discards volume names.
+# When $forceDir is set, returns paths with trailing slashes (or arrays
+# with trailing blank members).
+#
+# If third argument is a reference, returns volume information there.
+#
+# input output
+# . ('.') '.'
+# ./a ('a') a
+# ./a/b ('a','b') a/b
+# ./a/b/ ('a','b') a/b
+# a/b/ ('a','b') a/b
+# /a/b/ ('','a','b') /a/b
+# c:\a\b\c.doc ('','a','b','c.doc') /a/b/c.doc # on Windoze
+# "i/o maps:whatever" ('i_o maps', 'whatever') "i_o maps/whatever" # on Macs
+sub _asZipDirName
+{
+ my $name = shift;
+ my $forceDir = shift;
+ my $volReturn = shift;
+ my ( $volume, $directories, $file ) =
+ File::Spec->splitpath( File::Spec->canonpath($name), $forceDir );
+ $$volReturn = $volume if ( ref($volReturn) );
+ my @dirs = map { $_ =~ s{/}{_}g; $_ } File::Spec->splitdir($directories);
+ if ( @dirs > 0 ) { pop (@dirs) unless $dirs[-1] } # remove empty component
+ push ( @dirs, $file || '' );
+ #return wantarray ? @dirs : join ( '/', @dirs );
+ return join ( '/', @dirs );
+}
+
+# Return an absolute local name for a zip name.
+# Assume a directory if zip name has trailing slash.
+# Takes an optional volume name in FS format (like 'a:').
+#
+sub _asLocalName
+{
+ my $name = shift; # zip format
+ my $volume = shift;
+ $volume = '' unless defined($volume); # local FS format
+
+ my @paths = split ( /\//, $name );
+ my $filename = pop (@paths);
+ $filename = '' unless defined($filename);
+ my $localDirs = @paths?File::Spec->catdir(@paths):'';
+ my $localName = File::Spec->catpath( $volume, $localDirs, $filename );
+ $localName = File::Spec->rel2abs($localName) unless $volume;
+ return $localName;
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Archive::Zip - Provide an interface to ZIP archive files.
+
+=head1 SYNOPSIS
+
+ # Create a Zip file
+ use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
+ my $zip = Archive::Zip->new();
+
+ # Add a directory
+ my $dir_member = $zip->addDirectory( 'dirname/' );
+
+ # Add a file from a string with compression
+ my $string_member = $zip->addString( 'This is a test', 'stringMember.txt' );
+ $string_member->desiredCompressionMethod( COMPRESSION_DEFLATED );
+
+ # Add a file from disk
+ my $file_member = $zip->addFile( 'xyz.pl', 'AnotherName.pl' );
+
+ # Save the Zip file
+ unless ( $zip->writeToFileNamed('someZip.zip') == AZ_OK ) {
+ die 'write error';
+ }
+
+ # Read a Zip file
+ my $somezip = Archive::Zip->new();
+ unless ( $somezip->read( 'someZip.zip' ) == AZ_OK ) {
+ die 'read error';
+ }
+
+ # Change the compression type for a file in the Zip
+ my $member = $somezip->memberNamed( 'stringMember.txt' );
+ $member->desiredCompressionMethod( COMPRESSION_STORED );
+ unless ( $zip->writeToFileNamed( 'someOtherZip.zip' ) == AZ_OK ) {
+ die 'write error';
+ }
+
+=head1 DESCRIPTION
+
+The Archive::Zip module allows a Perl program to create, manipulate, read,
+and write Zip archive files.
+
+Zip archives can be created, or you can read from existing zip files.
+
+Once created, they can be written to files, streams, or strings. Members
+can be added, removed, extracted, replaced, rearranged, and enumerated.
+They can also be renamed or have their dates, comments, or other attributes
+queried or modified. Their data can be compressed or uncompressed as needed.
+
+Members can be created from members in existing Zip files, or from existing
+directories, files, or strings.
+
+This module uses the L<Compress::Zlib> library to read and write the
+compressed streams inside the files.
+
+=head2 File Naming
+
+Regardless of what your local file system uses for file naming, names in a
+Zip file are in Unix format (I<forward> slashes (/) separating directory
+names, etc.).
+
+C<Archive::Zip> tries to be consistent with file naming conventions, and will
+translate back and forth between native and Zip file names.
+
+However, it can't guess which format names are in. So two rules control what
+kind of file name you must pass various routines:
+
+=over 4
+
+=item Names of files are in local format.
+
+C<File::Spec> and C<File::Basename> are used for various file
+operations. When you're referring to a file on your system, use its
+file naming conventions.
+
+=item Names of archive members are in Unix format.
+
+This applies to every method that refers to an archive member, or
+provides a name for new archive members. The C<extract()> methods
+that can take one or two names will convert from local to zip names
+if you call them with a single name.
+
+=back
+
+=head2 Archive::Zip Object Model
+
+=head2 Overview
+
+Archive::Zip::Archive objects are what you ordinarily deal with.
+These maintain the structure of a zip file, without necessarily
+holding data. When a zip is read from a disk file, the (possibly
+compressed) data still lives in the file, not in memory. Archive
+members hold information about the individual members, but not
+(usually) the actual member data. When the zip is written to a
+(different) file, the member data is compressed or copied as needed.
+It is possible to make archive members whose data is held in a string
+in memory, but this is not done when a zip file is read. Directory
+members don't have any data.
+
+=head2 Inheritance
+
+ Exporter
+ Archive::Zip Common base class, has defs.
+ Archive::Zip::Archive A Zip archive.
+ Archive::Zip::Member Abstract superclass for all members.
+ Archive::Zip::StringMember Member made from a string
+ Archive::Zip::FileMember Member made from an external file
+ Archive::Zip::ZipFileMember Member that lives in a zip file
+ Archive::Zip::NewFileMember Member whose data is in a file
+ Archive::Zip::DirectoryMember Member that is a directory
+
+=head1 EXPORTS
+
+=over 4
+
+=item :CONSTANTS
+
+Exports the following constants:
+
+FA_MSDOS FA_UNIX GPBF_ENCRYPTED_MASK
+GPBF_DEFLATING_COMPRESSION_MASK GPBF_HAS_DATA_DESCRIPTOR_MASK
+COMPRESSION_STORED COMPRESSION_DEFLATED IFA_TEXT_FILE_MASK
+IFA_TEXT_FILE IFA_BINARY_FILE COMPRESSION_LEVEL_NONE
+COMPRESSION_LEVEL_DEFAULT COMPRESSION_LEVEL_FASTEST
+COMPRESSION_LEVEL_BEST_COMPRESSION
+
+=item :MISC_CONSTANTS
+
+Exports the following constants (only necessary for extending the
+module):
+
+FA_AMIGA FA_VAX_VMS FA_VM_CMS FA_ATARI_ST FA_OS2_HPFS
+FA_MACINTOSH FA_Z_SYSTEM FA_CPM FA_WINDOWS_NTFS
+GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK
+GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK
+GPBF_IS_COMPRESSED_PATCHED_DATA_MASK COMPRESSION_SHRUNK
+DEFLATING_COMPRESSION_NORMAL DEFLATING_COMPRESSION_MAXIMUM
+DEFLATING_COMPRESSION_FAST DEFLATING_COMPRESSION_SUPER_FAST
+COMPRESSION_REDUCED_1 COMPRESSION_REDUCED_2 COMPRESSION_REDUCED_3
+COMPRESSION_REDUCED_4 COMPRESSION_IMPLODED COMPRESSION_TOKENIZED
+COMPRESSION_DEFLATED_ENHANCED
+COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED
+
+=item :ERROR_CODES
+
+Explained below. Returned from most methods.
+
+AZ_OK AZ_STREAM_END AZ_ERROR AZ_FORMAT_ERROR AZ_IO_ERROR
+
+=back
+
+=head1 ERROR CODES
+
+Many of the methods in Archive::Zip return error codes. These are implemented
+as inline subroutines, using the C<use constant> pragma. They can be imported
+into your namespace using the C<:ERROR_CODES> tag:
+
+ use Archive::Zip qw( :ERROR_CODES );
+
+ ...
+
+ unless ( $zip->read( 'myfile.zip' ) == AZ_OK ) {
+ die "whoops!";
+ }
+
+=over 4
+
+=item AZ_OK (0)
+
+Everything is fine.
+
+=item AZ_STREAM_END (1)
+
+The read stream (or central directory) ended normally.
+
+=item AZ_ERROR (2)
+
+There was some generic kind of error.
+
+=item AZ_FORMAT_ERROR (3)
+
+There is a format error in a ZIP file being read.
+
+=item AZ_IO_ERROR (4)
+
+There was an IO error.
+
+=back
+
+=head2 Compression
+
+Archive::Zip allows each member of a ZIP file to be compressed (using the
+Deflate algorithm) or uncompressed.
+
+Other compression algorithms that some versions of ZIP have been able to
+produce are not supported. Each member has two compression methods: the
+one it's stored as (this is always COMPRESSION_STORED for string and external
+file members), and the one you desire for the member in the zip file.
+
+These can be different, of course, so you can make a zip member that is not
+compressed out of one that is, and vice versa.
+
+You can inquire about the current compression and set the desired
+compression method:
+
+ my $member = $zip->memberNamed( 'xyz.txt' );
+ $member->compressionMethod(); # return current compression
+
+ # set to read uncompressed
+ $member->desiredCompressionMethod( COMPRESSION_STORED );
+
+ # set to read compressed
+ $member->desiredCompressionMethod( COMPRESSION_DEFLATED );
+
+There are two different compression methods:
+
+=over 4
+
+=item COMPRESSION_STORED
+
+File is stored (no compression)
+
+=item COMPRESSION_DEFLATED
+
+File is Deflated
+
+=back
+
+=head2 Compression Levels
+
+If a member's desiredCompressionMethod is COMPRESSION_DEFLATED, you
+can choose different compression levels. This choice may affect the
+speed of compression and decompression, as well as the size of the
+compressed member data.
+
+ $member->desiredCompressionLevel( 9 );
+
+The levels given can be:
+
+=over 4
+
+=item 0 or COMPRESSION_LEVEL_NONE
+
+This is the same as saying
+
+ $member->desiredCompressionMethod( COMPRESSION_STORED );
+
+=item 1 .. 9
+
+1 gives the best speed and worst compression, and 9 gives the
+best compression and worst speed.
+
+=item COMPRESSION_LEVEL_FASTEST
+
+This is a synonym for level 1.
+
+=item COMPRESSION_LEVEL_BEST_COMPRESSION
+
+This is a synonym for level 9.
+
+=item COMPRESSION_LEVEL_DEFAULT
+
+This gives a good compromise between speed and compression,
+and is currently equivalent to 6 (this is in the zlib code).
+This is the level that will be used if not specified.
+
+=back
+
+=head1 Archive::Zip Methods
+
+The Archive::Zip class (and its invisible subclass Archive::Zip::Archive)
+implement generic zip file functionality. Creating a new Archive::Zip object
+actually makes an Archive::Zip::Archive object, but you don't have to worry
+about this unless you're subclassing.
+
+=head2 Constructor
+
+=over 4
+
+=item new( [$fileName] )
+
+Make a new, empty zip archive.
+
+ my $zip = Archive::Zip->new();
+
+If an additional argument is passed, new() will call read()
+to read the contents of an archive:
+
+ my $zip = Archive::Zip->new( 'xyz.zip' );
+
+If a filename argument is passed and the read fails for any
+reason, new will return undef. For this reason, it may be
+better to call read separately.
+
+=back
+
+=head2 Zip Archive Utility Methods
+
+These Archive::Zip methods may be called as functions or as object
+methods. Do not call them as class methods:
+
+ $zip = Archive::Zip->new();
+ $crc = Archive::Zip::computeCRC32( 'ghijkl' ); # OK
+ $crc = $zip->computeCRC32( 'ghijkl' ); # also OK
+ $crc = Archive::Zip->computeCRC32( 'ghijkl' ); # NOT OK
+
+=over 4
+
+=item Archive::Zip::computeCRC32( $string [, $crc] )
+
+This is a utility function that uses the Compress::Zlib CRC
+routine to compute a CRC-32. You can get the CRC of a string:
+
+ $crc = Archive::Zip::computeCRC32( $string );
+
+Or you can compute the running CRC:
+
+ $crc = 0;
+ $crc = Archive::Zip::computeCRC32( 'abcdef', $crc );
+ $crc = Archive::Zip::computeCRC32( 'ghijkl', $crc );
+
+=item Archive::Zip::setChunkSize( $number )
+
+Report or change chunk size used for reading and writing.
+This can make big differences in dealing with large files.
+Currently, this defaults to 32K. This also changes the chunk
+size used for Compress::Zlib. You must call setChunkSize()
+before reading or writing. This is not exportable, so you
+must call it like:
+
+ Archive::Zip::setChunkSize( 4096 );
+
+or as a method on a zip (though this is a global setting).
+Returns old chunk size.
+
+=item Archive::Zip::chunkSize()
+
+Returns the current chunk size:
+
+ my $chunkSize = Archive::Zip::chunkSize();
+
+=item Archive::Zip::setErrorHandler( \&subroutine )
+
+Change the subroutine called with error strings. This
+defaults to \&Carp::carp, but you may want to change it to
+get the error strings. This is not exportable, so you must
+call it like:
+
+ Archive::Zip::setErrorHandler( \&myErrorHandler );
+
+If myErrorHandler is undef, resets handler to default.
+Returns old error handler. Note that if you call Carp::carp
+or a similar routine or if you're chaining to the default
+error handler from your error handler, you may want to
+increment the number of caller levels that are skipped (do
+not just set it to a number):
+
+ $Carp::CarpLevel++;
+
+=item Archive::Zip::tempFile( [$tmpdir] )
+
+Create a uniquely named temp file. It will be returned open
+for read/write. If C<$tmpdir> is given, it is used as the
+name of a directory to create the file in. If not given,
+creates the file using C<File::Spec::tmpdir()>. Generally, you can
+override this choice using the
+
+ $ENV{TMPDIR}
+
+environment variable. But see the L<File::Spec|File::Spec>
+documentation for your system. Note that on many systems, if you're
+running in taint mode, then you must make sure that C<$ENV{TMPDIR}> is
+untainted for it to be used.
+Will I<NOT> create C<$tmpdir> if it doesn't exist (this is a change
+from prior versions!). Returns file handle and name:
+
+ my ($fh, $name) = Archive::Zip::tempFile();
+ my ($fh, $name) = Archive::Zip::tempFile('myTempDir');
+ my $fh = Archive::Zip::tempFile(); # if you don't need the name
+
+=back
+
+=head2 Zip Archive Accessors
+
+=over 4
+
+=item members()
+
+Return a copy of the members array
+
+ my @members = $zip->members();
+
+=item numberOfMembers()
+
+Return the number of members I have
+
+=item memberNames()
+
+Return a list of the (internal) file names of the zip members
+
+=item memberNamed( $string )
+
+Return ref to member whose filename equals given filename or
+undef. C<$string> must be in Zip (Unix) filename format.
+
+=item membersMatching( $regex )
+
+Return array of members whose filenames match given regular
+expression in list context. Returns number of matching
+members in scalar context.
+
+ my @textFileMembers = $zip->membersMatching( '.*\.txt' );
+ # or
+ my $numberOfTextFiles = $zip->membersMatching( '.*\.txt' );
+
+=item diskNumber()
+
+Return the disk that I start on. Not used for writing zips,
+but might be interesting if you read a zip in. This should be
+0, as Archive::Zip does not handle multi-volume archives.
+
+=item diskNumberWithStartOfCentralDirectory()
+
+Return the disk number that holds the beginning of the
+central directory. Not used for writing zips, but might be
+interesting if you read a zip in. This should be 0, as
+Archive::Zip does not handle multi-volume archives.
+
+=item numberOfCentralDirectoriesOnThisDisk()
+
+Return the number of CD structures in the zipfile last read in.
+Not used for writing zips, but might be interesting if you read a zip
+in.
+
+=item numberOfCentralDirectories()
+
+Return the number of CD structures in the zipfile last read in.
+Not used for writing zips, but might be interesting if you read a zip
+in.
+
+=item centralDirectorySize()
+
+Returns central directory size, as read from an external zip
+file. Not used for writing zips, but might be interesting if
+you read a zip in.
+
+=item centralDirectoryOffsetWRTStartingDiskNumber()
+
+Returns the offset into the zip file where the CD begins. Not
+used for writing zips, but might be interesting if you read a
+zip in.
+
+=item zipfileComment( [$string] )
+
+Get or set the zipfile comment. Returns the old comment.
+
+ print $zip->zipfileComment();
+ $zip->zipfileComment( 'New Comment' );
+
+=item eocdOffset()
+
+Returns the (unexpected) number of bytes between where the
+EOCD was found and where it expected to be. This is normally
+0, but would be positive if something (a virus, perhaps) had
+added bytes somewhere before the EOCD. Not used for writing
+zips, but might be interesting if you read a zip in. Here is
+an example of how you can diagnose this:
+
+ my $zip = Archive::Zip->new('somefile.zip');
+ if ($zip->eocdOffset())
+ {
+ warn "A virus has added ", $zip->eocdOffset, " bytes of garbage\n";
+ }
+
+The C<eocdOffset()> is used to adjust the starting position of member
+headers, if necessary.
+
+=item fileName()
+
+Returns the name of the file last read from. If nothing has
+been read yet, returns an empty string; if read from a file
+handle, returns the handle in string form.
+
+=back
+
+=head2 Zip Archive Member Operations
+
+Various operations on a zip file modify members. When a member is
+passed as an argument, you can either use a reference to the member
+itself, or the name of a member. Of course, using the name requires
+that names be unique within a zip (this is not enforced).
+
+=over 4
+
+=item removeMember( $memberOrName )
+
+Remove and return the given member, or match its name and
+remove it. Returns undef if member or name doesn't exist in this
+Zip. No-op if member does not belong to this zip.
+
+=item replaceMember( $memberOrName, $newMember )
+
+Remove and return the given member, or match its name and
+remove it. Replace with new member. Returns undef if member or
+name doesn't exist in this Zip, or if C<$newMember> is undefined.
+
+It is an (undiagnosed) error to provide a C<$newMember> that is a
+member of the zip being modified.
+
+ my $member1 = $zip->removeMember( 'xyz' );
+ my $member2 = $zip->replaceMember( 'abc', $member1 );
+ # now, $member2 (named 'abc') is not in $zip,
+ # and $member1 (named 'xyz') is, having taken $member2's place.
+
+=item extractMember( $memberOrName [, $extractedName ] )
+
+Extract the given member, or match its name and extract it.
+Returns undef if member doesn't exist in this Zip. If
+optional second arg is given, use it as the name of the
+extracted member. Otherwise, the internal filename of the
+member is used as the name of the extracted file or
+directory.
+If you pass C<$extractedName>, it should be in the local file
+system's format.
+All necessary directories will be created. Returns C<AZ_OK>
+on success.
+
+=item extractMemberWithoutPaths( $memberOrName [, $extractedName ] )
+
+Extract the given member, or match its name and extract it.
+Does not use path information (extracts into the current
+directory). Returns undef if member doesn't exist in this
+Zip.
+If optional second arg is given, use it as the name of the
+extracted member (its paths will be deleted too). Otherwise,
+the internal filename of the member (minus paths) is used as
+the name of the extracted file or directory. Returns C<AZ_OK>
+on success.
+
+=item addMember( $member )
+
+Append a member (possibly from another zip file) to the zip
+file. Returns the new member. Generally, you will use
+addFile(), addDirectory(), addFileOrDirectory(), addString(),
+or read() to add members.
+
+ # Move member named 'abc' to end of zip:
+ my $member = $zip->removeMember( 'abc' );
+ $zip->addMember( $member );
+
+=item updateMember( $memberOrName, $fileName )
+
+Update a single member from the file or directory named C<$fileName>.
+Returns the (possibly added or updated) member, if any; C<undef> on
+errors.
+The comparison is based on C<lastModTime()> and (in the case of a
+non-directory) the size of the file.
+
+=item addFile( $fileName [, $newName ] )
+
+Append a member whose data comes from an external file,
+returning the member or undef. The member will have its file
+name set to the name of the external file, and its
+desiredCompressionMethod set to COMPRESSION_DEFLATED. The
+file attributes and last modification time will be set from
+the file.
+If the name given does not represent a readable plain file or
+symbolic link, undef will be returned. C<$fileName> must be
+in the format required for the local file system.
+The optional C<$newName> argument sets the internal file name
+to something different than the given $fileName. C<$newName>,
+if given, must be in Zip name format (i.e. Unix).
+The text mode bit will be set if the contents appears to be
+text (as returned by the C<-T> perl operator).
+
+
+I<NOTE> that you shouldn't (generally) use absolute path names
+in zip member names, as this will cause problems with some zip
+tools as well as introduce a security hole and make the zip
+harder to use.
+
+=item addDirectory( $directoryName [, $fileName ] )
+
+
+
+Append a member created from the given directory name. The
+directory name does not have to name an existing directory.
+If the named directory exists, the file modification time and
+permissions are set from the existing directory, otherwise
+they are set to now and permissive default permissions.
+C<$directoryName> must be in local file system format.
+The optional second argument sets the name of the archive
+member (which defaults to C<$directoryName>). If given, it
+must be in Zip (Unix) format.
+Returns the new member.
+
+=item addFileOrDirectory( $name [, $newName ] )
+
+
+
+Append a member from the file or directory named $name. If
+$newName is given, use it for the name of the new member.
+Will add or remove trailing slashes from $newName as needed.
+C<$name> must be in local file system format.
+The optional second argument sets the name of the archive
+member (which defaults to C<$name>). If given, it must be in
+Zip (Unix) format.
+
+=item addString( $stringOrStringRef, $name )
+
+
+
+Append a member created from the given string or string
+reference. The name is given by the second argument.
+Returns the new member. The last modification time will be
+set to now, and the file attributes will be set to permissive
+defaults.
+
+ my $member = $zip->addString( 'This is a test', 'test.txt' );
+
+=item contents( $memberOrMemberName [, $newContents ] )
+
+
+
+Returns the uncompressed data for a particular member, or
+undef.
+
+ print "xyz.txt contains " . $zip->contents( 'xyz.txt' );
+
+Also can change the contents of a member:
+
+ $zip->contents( 'xyz.txt', 'This is the new contents' );
+
+If called expecting an array as the return value, it will include
+the status as the second value in the array.
+
+ ($content, $status) = $zip->contents( 'xyz.txt');
+
+=back
+
+=head2 Zip Archive I/O operations
+
+
+A Zip archive can be written to a file or file handle, or read from
+one.
+
+=over 4
+
+=item writeToFileNamed( $fileName )
+
+
+
+Write a zip archive to named file. Returns C<AZ_OK> on
+success.
+
+ my $status = $zip->writeToFileNamed( 'xx.zip' );
+ die "error somewhere" if $status != AZ_OK;
+
+Note that if you use the same name as an existing zip file
+that you read in, you will clobber ZipFileMembers. So
+instead, write to a different file name, then delete the
+original.
+If you use the C<overwrite()> or C<overwriteAs()> methods, you can
+re-write the original zip in this way.
+C<$fileName> should be a valid file name on your system.
+
+=item writeToFileHandle( $fileHandle [, $seekable] )
+
+Write a zip archive to a file handle. Return AZ_OK on
+success. The optional second arg tells whether or not to try
+to seek backwards to re-write headers. If not provided, it is
+set if the Perl C<-f> test returns true. This could fail on
+some operating systems, though.
+
+ my $fh = IO::File->new( 'someFile.zip', 'w' );
+ unless ( $zip->writeToFileHandle( $fh ) != AZ_OK ) {
+ # error handling
+ }
+
+If you pass a file handle that is not seekable (like if
+you're writing to a pipe or a socket), pass a false second
+argument:
+
+ my $fh = IO::File->new( '| cat > somefile.zip', 'w' );
+ $zip->writeToFileHandle( $fh, 0 ); # fh is not seekable
+
+If this method fails during the write of a member, that
+member and all following it will return false from
+C<wasWritten()>. See writeCentralDirectory() for a way to
+deal with this.
+If you want, you can write data to the file handle before
+passing it to writeToFileHandle(); this could be used (for
+instance) for making self-extracting archives. However, this
+only works reliably when writing to a real file (as opposed
+to STDOUT or some other possible non-file).
+
+See examples/selfex.pl for how to write a self-extracting
+archive.
+
+=item writeCentralDirectory( $fileHandle [, $offset ] )
+
+Writes the central directory structure to the given file
+handle.
+
+Returns AZ_OK on success. If given an $offset, will
+seek to that point before writing. This can be used for
+recovery in cases where writeToFileHandle or writeToFileNamed
+returns an IO error because of running out of space on the
+destination file.
+
+You can truncate the zip by seeking backwards and then writing the
+directory:
+
+ my $fh = IO::File->new( 'someFile.zip', 'w' );
+ my $retval = $zip->writeToFileHandle( $fh );
+ if ( $retval == AZ_IO_ERROR ) {
+ my @unwritten = grep { not $_->wasWritten() } $zip->members();
+ if (@unwritten) {
+ $zip->removeMember( $member ) foreach my $member ( @unwritten );
+ $zip->writeCentralDirectory( $fh,
+ $unwritten[0]->writeLocalHeaderRelativeOffset());
+ }
+ }
+
+=item overwriteAs( $newName )
+
+Write the zip to the specified file, as safely as possible.
+This is done by first writing to a temp file, then renaming
+the original if it exists, then renaming the temp file, then
+deleting the renamed original if it exists. Returns AZ_OK if
+successful.
+
+=item overwrite()
+
+Write back to the original zip file. See overwriteAs() above.
+If the zip was not ever read from a file, this generates an
+error.
+
+=item read( $fileName )
+
+Read zipfile headers from a zip file, appending new members.
+Returns C<AZ_OK> or error code.
+
+ my $zipFile = Archive::Zip->new();
+ my $status = $zipFile->read( '/some/FileName.zip' );
+
+=item readFromFileHandle( $fileHandle, $filename )
+
+Read zipfile headers from an already-opened file handle,
+appending new members. Does not close the file handle.
+Returns C<AZ_OK> or error code. Note that this requires a
+seekable file handle; reading from a stream is not yet
+supported.
+
+ my $fh = IO::File->new( '/some/FileName.zip', 'r' );
+ my $zip1 = Archive::Zip->new();
+ my $status = $zip1->readFromFileHandle( $fh );
+ my $zip2 = Archive::Zip->new();
+ $status = $zip2->readFromFileHandle( $fh );
+
+=back
+
+=head2 Zip Archive Tree operations
+
+These used to be in Archive::Zip::Tree but got moved into
+Archive::Zip. They enable operation on an entire tree of members or
+files.
+A usage example:
+
+ use Archive::Zip;
+ my $zip = Archive::Zip->new();
+
+ # add all readable files and directories below . as xyz/*
+ $zip->addTree( '.', 'xyz' );
+
+ # add all readable plain files below /abc as def/*
+ $zip->addTree( '/abc', 'def', sub { -f && -r } );
+
+ # add all .c files below /tmp as stuff/*
+ $zip->addTreeMatching( '/tmp', 'stuff', '\.c$' );
+
+ # add all .o files below /tmp as stuff/* if they aren't writable
+ $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { ! -w } );
+
+ # add all .so files below /tmp that are smaller than 200 bytes as stuff/*
+ $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { -s < 200 } );
+
+ # and write them into a file
+ $zip->writeToFileNamed('xxx.zip');
+
+ # now extract the same files into /tmpx
+ $zip->extractTree( 'stuff', '/tmpx' );
+
+=over 4
+
+=item $zip->addTree( $root, $dest [,$pred] ) -- Add tree of files to a zip
+
+C<$root> is the root of the tree of files and directories to be
+added. It is a valid directory name on your system. C<$dest> is
+the name for the root in the zip file (undef or blank means
+to use relative pathnames). It is a valid ZIP directory name
+(that is, it uses forward slashes (/) for separating
+directory components). C<$pred> is an optional subroutine
+reference to select files: it is passed the name of the
+prospective file or directory using C<$_>, and if it returns
+true, the file or directory will be included. The default is
+to add all readable files and directories. For instance,
+using
+
+ my $pred = sub { /\.txt/ };
+ $zip->addTree( '.', '', $pred );
+
+will add all the .txt files in and below the current
+directory, using relative names, and making the names
+identical in the zipfile:
+
+ original name zip member name
+ ./xyz xyz
+ ./a/ a/
+ ./a/b a/b
+
+To translate absolute to relative pathnames, just pass them
+in: $zip->addTree( '/c/d', 'a' );
+
+ original name zip member name
+ /c/d/xyz a/xyz
+ /c/d/a/ a/a/
+ /c/d/a/b a/a/b
+
+Returns AZ_OK on success. Note that this will not follow
+symbolic links to directories. Note also that this does not
+check for the validity of filenames.
+
+Note that you generally I<don't> want to make zip archive member names
+absolute.
+
+=item $zip->addTreeMatching( $root, $dest, $pattern [,$pred] )
+
+$root is the root of the tree of files and directories to be
+added $dest is the name for the root in the zip file (undef
+means to use relative pathnames) $pattern is a (non-anchored)
+regular expression for filenames to match $pred is an
+optional subroutine reference to select files: it is passed
+the name of the prospective file or directory in C<$_>, and
+if it returns true, the file or directory will be included.
+The default is to add all readable files and directories. To
+add all files in and below the current dirctory whose names
+end in C<.pl>, and make them extract into a subdirectory
+named C<xyz>, do this:
+
+ $zip->addTreeMatching( '.', 'xyz', '\.pl$' )
+
+To add all I<writable> files in and below the dirctory named
+C</abc> whose names end in C<.pl>, and make them extract into
+a subdirectory named C<xyz>, do this:
+
+ $zip->addTreeMatching( '/abc', 'xyz', '\.pl$', sub { -w } )
+
+Returns AZ_OK on success. Note that this will not follow
+symbolic links to directories.
+
+=item $zip->updateTree( $root, [ $dest, [ $pred [, $mirror]]] );
+
+
+
+Update a zip file from a directory tree.
+
+C<updateTree()> takes the same arguments as C<addTree()>, but first
+checks to see whether the file or directory already exists in the zip
+file, and whether it has been changed.
+
+If the fourth argument C<$mirror> is true, then delete all my members
+if corresponding files weren't found.
+
+
+Returns an error code or AZ_OK if all is well.
+
+=item $zip->extractTree()
+
+
+
+=item $zip->extractTree( $root )
+
+
+
+=item $zip->extractTree( $root, $dest )
+
+
+
+=item $zip->extractTree( $root, $dest, $volume )
+
+
+
+If you don't give any arguments at all, will extract all the
+files in the zip with their original names.
+
+
+If you supply one argument for C<$root>, C<extractTree> will extract
+all the members whose names start with C<$root> into the current
+directory, stripping off C<$root> first.
+C<$root> is in Zip (Unix) format.
+For instance,
+
+ $zip->extractTree( 'a' );
+
+when applied to a zip containing the files:
+a/x a/b/c ax/d/e d/e will extract:
+
+
+a/x as ./x
+
+
+a/b/c as ./b/c
+
+
+If you give two arguments, C<extractTree> extracts all the members
+whose names start with C<$root>. It will translate C<$root> into
+C<$dest> to construct the destination file name.
+C<$root> and C<$dest> are in Zip (Unix) format.
+For instance,
+
+ $zip->extractTree( 'a', 'd/e' );
+
+when applied to a zip containing the files:
+a/x a/b/c ax/d/e d/e will extract:
+
+
+a/x to d/e/x
+
+
+a/b/c to d/e/b/c and ignore ax/d/e and d/e
+
+
+If you give three arguments, C<extractTree> extracts all the members
+whose names start with C<$root>. It will translate C<$root> into
+C<$dest> to construct the destination file name, and then it will
+convert to local file system format, using C<$volume> as the name of
+the destination volume.
+
+
+C<$root> and C<$dest> are in Zip (Unix) format.
+
+
+C<$volume> is in local file system format.
+
+
+For instance, under Windows,
+
+ $zip->extractTree( 'a', 'd/e', 'f:' );
+
+when applied to a zip containing the files:
+a/x a/b/c ax/d/e d/e will extract:
+
+
+a/x to f:d/e/x
+
+
+a/b/c to f:d/e/b/c and ignore ax/d/e and d/e
+
+
+If you want absolute paths (the prior example used paths relative to
+the current directory on the destination volume, you can specify these
+in C<$dest>:
+
+ $zip->extractTree( 'a', '/d/e', 'f:' );
+
+when applied to a zip containing the files:
+a/x a/b/c ax/d/e d/e will extract:
+
+
+a/x to f:\d\e\x
+
+
+a/b/c to f:\d\e\b\c and ignore ax/d/e and d/e
+
+Returns an error code or AZ_OK if everything worked OK.
+
+=back
+
+=head1 MEMBER OPERATIONS
+
+
+=head2 Member Class Methods
+
+
+Several constructors allow you to construct members without adding
+them to a zip archive. These work the same as the addFile(),
+addDirectory(), and addString() zip instance methods described above,
+but they don't add the new members to a zip.
+
+=over 4
+
+=item Archive::Zip::Member->newFromString( $stringOrStringRef [, $fileName] )
+
+
+
+Construct a new member from the given string. Returns undef
+on error.
+
+ my $member = Archive::Zip::Member->newFromString( 'This is a test',
+ 'xyz.txt' );
+
+=item newFromFile( $fileName )
+
+
+
+Construct a new member from the given file. Returns undef on
+error.
+
+ my $member = Archive::Zip::Member->newFromFile( 'xyz.txt' );
+
+=item newDirectoryNamed( $directoryName [, $zipname ] )
+
+
+
+Construct a new member from the given directory.
+C<$directoryName> must be a valid name on your file system; it doesn't
+have to exist.
+
+
+If given, C<$zipname> will be the name of the zip member; it must be a
+valid Zip (Unix) name. If not given, it will be converted from
+C<$directoryName>.
+
+
+Returns undef on error.
+
+ my $member = Archive::Zip::Member->newDirectoryNamed( 'CVS/' );
+
+=back
+
+=head2 Member Simple accessors
+
+
+These methods get (and/or set) member attribute values.
+
+=over 4
+
+=item versionMadeBy()
+
+
+
+Gets the field from the member header.
+
+=item fileAttributeFormat( [$format] )
+
+
+
+Gets or sets the field from the member header. These are
+C<FA_*> values.
+
+=item versionNeededToExtract()
+
+
+
+Gets the field from the member header.
+
+=item bitFlag()
+
+
+
+Gets the general purpose bit field from the member header.
+This is where the C<GPBF_*> bits live.
+
+=item compressionMethod()
+
+
+
+Returns the member compression method. This is the method
+that is currently being used to compress the member data.
+This will be COMPRESSION_STORED for added string or file
+members, or any of the C<COMPRESSION_*> values for members
+from a zip file. However, this module can only handle members
+whose data is in COMPRESSION_STORED or COMPRESSION_DEFLATED
+format.
+
+=item desiredCompressionMethod( [$method] )
+
+
+
+Get or set the member's C<desiredCompressionMethod>. This is
+the compression method that will be used when the member is
+written. Returns prior desiredCompressionMethod. Only
+COMPRESSION_DEFLATED or COMPRESSION_STORED are valid
+arguments. Changing to COMPRESSION_STORED will change the
+member desiredCompressionLevel to 0; changing to
+COMPRESSION_DEFLATED will change the member
+desiredCompressionLevel to COMPRESSION_LEVEL_DEFAULT.
+
+=item desiredCompressionLevel( [$method] )
+
+
+
+Get or set the member's desiredCompressionLevel This is the
+method that will be used to write. Returns prior
+desiredCompressionLevel. Valid arguments are 0 through 9,
+COMPRESSION_LEVEL_NONE, COMPRESSION_LEVEL_DEFAULT,
+COMPRESSION_LEVEL_BEST_COMPRESSION, and
+COMPRESSION_LEVEL_FASTEST. 0 or COMPRESSION_LEVEL_NONE will
+change the desiredCompressionMethod to COMPRESSION_STORED.
+All other arguments will change the desiredCompressionMethod
+to COMPRESSION_DEFLATED.
+
+=item externalFileName()
+
+
+
+Return the member's external file name, if any, or undef.
+
+=item fileName()
+
+
+
+Get or set the member's internal filename. Returns the
+(possibly new) filename. Names will have backslashes
+converted to forward slashes, and will have multiple
+consecutive slashes converted to single ones.
+
+=item lastModFileDateTime()
+
+
+
+Return the member's last modification date/time stamp in
+MS-DOS format.
+
+=item lastModTime()
+
+
+
+Return the member's last modification date/time stamp,
+converted to unix localtime format.
+
+ print "Mod Time: " . scalar( localtime( $member->lastModTime() ) );
+
+=item setLastModFileDateTimeFromUnix()
+
+Set the member's lastModFileDateTime from the given unix
+time.
+
+ $member->setLastModFileDateTimeFromUnix( time() );
+
+=item internalFileAttributes()
+
+Return the internal file attributes field from the zip
+header. This is only set for members read from a zip file.
+
+=item externalFileAttributes()
+
+Return member attributes as read from the ZIP file. Note that
+these are NOT UNIX!
+
+=item unixFileAttributes( [$newAttributes] )
+
+Get or set the member's file attributes using UNIX file
+attributes. Returns old attributes.
+
+ my $oldAttribs = $member->unixFileAttributes( 0666 );
+
+Note that the return value has more than just the file
+permissions, so you will have to mask off the lowest bits for
+comparisions.
+
+=item localExtraField( [$newField] )
+
+Gets or sets the extra field that was read from the local
+header. This is not set for a member from a zip file until
+after the member has been written out. The extra field must
+be in the proper format.
+
+=item cdExtraField( [$newField] )
+
+Gets or sets the extra field that was read from the central
+directory header. The extra field must be in the proper
+format.
+
+=item extraFields()
+
+Return both local and CD extra fields, concatenated.
+
+=item fileComment( [$newComment] )
+
+Get or set the member's file comment.
+
+=item hasDataDescriptor()
+
+Get or set the data descriptor flag. If this is set, the
+local header will not necessarily have the correct data
+sizes. Instead, a small structure will be stored at the end
+of the member data with these values. This should be
+transparent in normal operation.
+
+=item crc32()
+
+Return the CRC-32 value for this member. This will not be set
+for members that were constructed from strings or external
+files until after the member has been written.
+
+=item crc32String()
+
+Return the CRC-32 value for this member as an 8 character
+printable hex string. This will not be set for members that
+were constructed from strings or external files until after
+the member has been written.
+
+=item compressedSize()
+
+Return the compressed size for this member. This will not be
+set for members that were constructed from strings or
+external files until after the member has been written.
+
+=item uncompressedSize()
+
+Return the uncompressed size for this member.
+
+=item isEncrypted()
+
+Return true if this member is encrypted. The Archive::Zip
+module does not currently create or extract encrypted
+members.
+
+=item isTextFile( [$flag] )
+
+Returns true if I am a text file. Also can set the status if
+given an argument (then returns old state). Note that this
+module does not currently do anything with this flag upon
+extraction or storage. That is, bytes are stored in native
+format whether or not they came from a text file.
+
+=item isBinaryFile()
+
+Returns true if I am a binary file. Also can set the status
+if given an argument (then returns old state). Note that this
+module does not currently do anything with this flag upon
+extraction or storage. That is, bytes are stored in native
+format whether or not they came from a text file.
+
+=item extractToFileNamed( $fileName )
+
+Extract me to a file with the given name. The file will be
+created with default modes. Directories will be created as
+needed.
+The C<$fileName> argument should be a valid file name on your
+file system.
+Returns AZ_OK on success.
+
+=item isDirectory()
+
+Returns true if I am a directory.
+
+=item writeLocalHeaderRelativeOffset()
+
+Returns the file offset in bytes the last time I was written.
+
+=item wasWritten()
+
+Returns true if I was successfully written. Reset at the
+beginning of a write attempt.
+
+=back
+
+=head2 Low-level member data reading
+
+It is possible to use lower-level routines to access member data
+streams, rather than the extract* methods and contents(). For
+instance, here is how to print the uncompressed contents of a member
+in chunks using these methods:
+
+ my ( $member, $status, $bufferRef );
+ $member = $zip->memberNamed( 'xyz.txt' );
+ $member->desiredCompressionMethod( COMPRESSION_STORED );
+ $status = $member->rewindData();
+ die "error $status" unless $status == AZ_OK;
+ while ( ! $member->readIsDone() )
+ {
+ ( $bufferRef, $status ) = $member->readChunk();
+ die "error $status"
+ if $status != AZ_OK && $status != AZ_STREAM_END;
+ # do something with $bufferRef:
+ print $$bufferRef;
+ }
+ $member->endRead();
+
+=over 4
+
+=item readChunk( [$chunkSize] )
+
+This reads the next chunk of given size from the member's
+data stream and compresses or uncompresses it as necessary,
+returning a reference to the bytes read and a status. If size
+argument is not given, defaults to global set by
+Archive::Zip::setChunkSize. Status is AZ_OK on success until
+the last chunk, where it returns AZ_STREAM_END. Returns C<(
+\$bytes, $status)>.
+
+ my ( $outRef, $status ) = $self->readChunk();
+ print $$outRef if $status != AZ_OK && $status != AZ_STREAM_END;
+
+=item rewindData()
+
+Rewind data and set up for reading data streams or writing
+zip files. Can take options for C<inflateInit()> or
+C<deflateInit()>, but this isn't likely to be necessary.
+Subclass overrides should call this method. Returns C<AZ_OK>
+on success.
+
+=item endRead()
+
+Reset the read variables and free the inflater or deflater.
+Must be called to close files, etc. Returns AZ_OK on success.
+
+=item readIsDone()
+
+Return true if the read has run out of data or errored out.
+
+=item contents()
+
+Return the entire uncompressed member data or undef in scalar
+context. When called in array context, returns C<( $string,
+$status )>; status will be AZ_OK on success:
+
+ my $string = $member->contents();
+ # or
+ my ( $string, $status ) = $member->contents();
+ die "error $status" unless $status == AZ_OK;
+
+Can also be used to set the contents of a member (this may
+change the class of the member):
+
+ $member->contents( "this is my new contents" );
+
+=item extractToFileHandle( $fh )
+
+Extract (and uncompress, if necessary) the member's contents
+to the given file handle. Return AZ_OK on success.
+
+=back
+
+=head1 Archive::Zip::FileMember methods
+
+The Archive::Zip::FileMember class extends Archive::Zip::Member. It is the
+base class for both ZipFileMember and NewFileMember classes. This class adds
+an C<externalFileName> and an C<fh> member to keep track of the external
+file.
+
+=over 4
+
+=item externalFileName()
+
+Return the member's external filename.
+
+=item fh()
+
+Return the member's read file handle. Automatically opens file if
+necessary.
+
+=back
+
+=head1 Archive::Zip::ZipFileMember methods
+
+The Archive::Zip::ZipFileMember class represents members that have been read
+from external zip files.
+
+=over 4
+
+=item diskNumberStart()
+
+Returns the disk number that the member's local header resides in.
+Should be 0.
+
+=item localHeaderRelativeOffset()
+
+Returns the offset into the zip file where the member's local header
+is.
+
+=item dataOffset()
+
+Returns the offset from the beginning of the zip file to the member's
+data.
+
+=back
+
+=head1 REQUIRED MODULES
+
+L<Archive::Zip> requires several other modules:
+
+L<Carp>
+
+L<Compress::Zlib>
+
+L<Cwd>
+
+L<File::Basename>
+
+L<File::Copy>
+
+L<File::Find>
+
+L<File::Path>
+
+L<File::Spec>
+
+L<File::Spec>
+
+L<IO::File>
+
+L<IO::Seekable>
+
+L<Time::Local>
+
+=head1 BUGS AND CAVEATS
+
+=head2 When not to use Archive::Zip
+
+If you are just going to be extracting zips (and/or other archives) you
+are recommended to look at using L<Archive::Extract> instead, as it is much
+easier to use and factors out archive-specific functionality.
+
+=head2 Try to avoid IO::Scalar
+
+One of the most common ways to use Archive::Zip is to generate Zip files
+in-memory. Most people have use L<IO::Scalar> for this purpose.
+
+Unfortunately, as of 1.11 this module no longer works with L<IO::Scalar>
+as it incorrectly implements seeking.
+
+Anybody using L<IO::Scalar> should consider porting to L<IO::String>,
+which is smaller, lighter, and is implemented to be perfectly compatible
+with regular seekable filehandles.
+
+Support for L<IO::Scalar> most likely will B<not> be restored in the
+future, as L<IO::Scalar> itself cannot change the way it is implemented
+due to back-compatibility issues.
+
+=head1 TO DO
+
+* auto-choosing storing vs compression
+
+* extra field hooks (see notes.txt)
+
+* check for dups on addition/renaming?
+
+* Text file extraction (line end translation)
+
+* Reading zip files from non-seekable inputs
+ (Perhaps by proxying through IO::String?)
+
+* separate unused constants into separate module
+
+* cookbook style docs
+
+* Handle tainted paths correctly
+
+* Work on better compatability with other IO:: modules
+
+=head1 SUPPORT
+
+Bugs should be reported via the CPAN bug tracker
+
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Archive-Zip>
+
+For other issues contact the maintainer
+
+=head1 AUTHOR
+
+Adam Kennedy E<lt>adamk at cpan.orgE<gt>
+
+Previously maintained by Steve Peters E<lt>steve at fisharerojo.orgE<gt>.
+
+File attributes code by Maurice Aubrey E<lt>maurice at lovelyfilth.comE<gt>.
+
+Originally by Ned Konz E<lt>nedkonz at cpan.orgE<gt>.
+
+=head1 COPYRIGHT
+
+Copyright (c) 2000-2004 Ned Konz. All rights reserved.
+
+Some parts copyright (c) 2005 Steve Peters. All rights reserved.
+
+Some parts copyright (c) 2006 Adam Kennedy. All rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Compress::Zlib>, L<Archive::Tar>, L<Archive::Extract>
+
+There is a Japanese translation of this
+document at L<http://www.memb.jp/~deq/perl/doc-ja/Archive-Zip.html> that
+was done by DEQ E<lt>deq at oct.zaq.ne.jpE<gt> . Thanks!
+
+=cut
Propchange: trunk/server/CPAN/Archive/Zip.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/CPAN/Archive/Zip.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/CPAN/Archive/Zip.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: trunk/server/CPAN/Archive/Zip/Archive.pm
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip/Archive.pm?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip/Archive.pm (added)
+++ trunk/server/CPAN/Archive/Zip/Archive.pm Thu Dec 21 14:28:39 2006
@@ -1,0 +1,786 @@
+package Archive::Zip::Archive;
+
+# Represents a generic ZIP archive
+
+use strict;
+use File::Path;
+use File::Find ();
+use File::Spec ();
+use File::Copy ();
+use File::Basename;
+use Cwd;
+
+use vars qw( $VERSION @ISA );
+
+BEGIN {
+ $VERSION = '1.18';
+ @ISA = qw( Archive::Zip );
+}
+
+use Archive::Zip qw(
+ :CONSTANTS
+ :ERROR_CODES
+ :PKZIP_CONSTANTS
+ :UTILITY_METHODS
+);
+
+# Note that this returns undef on read errors, else new zip object.
+
+sub new {
+ my $class = shift;
+ my $self = bless(
+ {
+ 'diskNumber' => 0,
+ 'diskNumberWithStartOfCentralDirectory' => 0,
+ 'numberOfCentralDirectoriesOnThisDisk' => 0, # shld be # of members
+ 'numberOfCentralDirectories' => 0, # shld be # of members
+ 'centralDirectorySize' => 0, # must re-compute on write
+ 'centralDirectoryOffsetWRTStartingDiskNumber' =>
+ 0, # must re-compute
+ 'writeEOCDOffset' => 0,
+ 'writeCentralDirectoryOffset' => 0,
+ 'zipfileComment' => '',
+ 'eocdOffset' => 0,
+ 'fileName' => ''
+ },
+ $class
+ );
+ $self->{'members'} = [];
+ if (@_) {
+ my $status = $self->read(@_);
+ return $status == AZ_OK ? $self : undef;
+ }
+ return $self;
+}
+
+sub members {
+ @{ shift->{'members'} };
+}
+
+sub numberOfMembers {
+ scalar( shift->members() );
+}
+
+sub memberNames {
+ my $self = shift;
+ return map { $_->fileName() } $self->members();
+}
+
+# return ref to member with given name or undef
+sub memberNamed {
+ my ( $self, $fileName ) = @_;
+ foreach my $member ( $self->members() ) {
+ return $member if $member->fileName() eq $fileName;
+ }
+ return undef;
+}
+
+sub membersMatching {
+ my ( $self, $pattern ) = @_;
+ return grep { $_->fileName() =~ /$pattern/ } $self->members();
+}
+
+sub diskNumber {
+ shift->{'diskNumber'};
+}
+
+sub diskNumberWithStartOfCentralDirectory {
+ shift->{'diskNumberWithStartOfCentralDirectory'};
+}
+
+sub numberOfCentralDirectoriesOnThisDisk {
+ shift->{'numberOfCentralDirectoriesOnThisDisk'};
+}
+
+sub numberOfCentralDirectories {
+ shift->{'numberOfCentralDirectories'};
+}
+
+sub centralDirectorySize {
+ shift->{'centralDirectorySize'};
+}
+
+sub centralDirectoryOffsetWRTStartingDiskNumber {
+ shift->{'centralDirectoryOffsetWRTStartingDiskNumber'};
+}
+
+sub zipfileComment {
+ my $self = shift;
+ my $comment = $self->{'zipfileComment'};
+ if (@_) {
+ $self->{'zipfileComment'} = pack( 'C0a*', shift() ); # avoid unicode
+ }
+ return $comment;
+}
+
+sub eocdOffset {
+ shift->{'eocdOffset'};
+}
+
+# Return the name of the file last read.
+sub fileName {
+ shift->{'fileName'};
+}
+
+sub removeMember {
+ my ( $self, $member ) = @_;
+ $member = $self->memberNamed($member) unless ref($member);
+ return undef unless $member;
+ my @newMembers = grep { $_ != $member } $self->members();
+ $self->{'members'} = \@newMembers;
+ return $member;
+}
+
+sub replaceMember {
+ my ( $self, $oldMember, $newMember ) = @_;
+ $oldMember = $self->memberNamed($oldMember) unless ref($oldMember);
+ return undef unless $oldMember;
+ return undef unless $newMember;
+ my @newMembers =
+ map { ( $_ == $oldMember ) ? $newMember : $_ } $self->members();
+ $self->{'members'} = \@newMembers;
+ return $oldMember;
+}
+
+sub extractMember {
+ my $self = shift;
+ my $member = shift;
+ $member = $self->memberNamed($member) unless ref($member);
+ return _error('member not found') unless $member;
+ my $originalSize = $member->compressedSize();
+ my $name = shift; # local FS name if given
+ my ( $volumeName, $dirName, $fileName );
+ if ( defined($name) ) {
+ ( $volumeName, $dirName, $fileName ) = File::Spec->splitpath($name);
+ $dirName = File::Spec->catpath( $volumeName, $dirName, '' );
+ }
+ else {
+ $name = $member->fileName();
+ ( $dirName = $name ) =~ s{[^/]*$}{};
+ $dirName = Archive::Zip::_asLocalName($dirName);
+ $name = Archive::Zip::_asLocalName($name);
+ }
+ if ( $dirName && !-d $dirName ) {
+ mkpath($dirName);
+ return _ioError("can't create dir $dirName") if ( !-d $dirName );
+ }
+ my $rc = $member->extractToFileNamed( $name, @_ );
+
+ # TODO refactor this fix into extractToFileNamed()
+ $member->{'compressedSize'} = $originalSize;
+ return $rc;
+}
+
+sub extractMemberWithoutPaths {
+ my $self = shift;
+ my $member = shift;
+ $member = $self->memberNamed($member) unless ref($member);
+ return _error('member not found') unless $member;
+ my $originalSize = $member->compressedSize();
+ return AZ_OK if $member->isDirectory();
+ my $name = shift;
+ unless ($name) {
+ $name = $member->fileName();
+ $name =~ s{.*/}{}; # strip off directories, if any
+ $name = Archive::Zip::_asLocalName($name);
+ }
+ my $rc = $member->extractToFileNamed( $name, @_ );
+ $member->{'compressedSize'} = $originalSize;
+ return $rc;
+}
+
+sub addMember {
+ my ( $self, $newMember ) = @_;
+ push( @{ $self->{'members'} }, $newMember ) if $newMember;
+ return $newMember;
+}
+
+sub addFile {
+ my $self = shift;
+ my $fileName = shift;
+ my $newName = shift;
+ my $newMember = $self->ZIPMEMBERCLASS->newFromFile( $fileName, $newName );
+ $self->addMember($newMember) if defined($newMember);
+ return $newMember;
+}
+
+sub addString {
+ my $self = shift;
+ my $newMember = $self->ZIPMEMBERCLASS->newFromString(@_);
+ return $self->addMember($newMember);
+}
+
+sub addDirectory {
+ my ( $self, $name, $newName ) = @_;
+ my $newMember = $self->ZIPMEMBERCLASS->newDirectoryNamed( $name, $newName );
+ $self->addMember($newMember);
+ return $newMember;
+}
+
+# add either a file or a directory.
+
+sub addFileOrDirectory {
+ my ( $self, $name, $newName ) = @_;
+ if ( -f $name ) {
+ ( $newName =~ s{/$}{} ) if $newName;
+ return $self->addFile( $name, $newName );
+ }
+ elsif ( -d $name ) {
+ ( $newName =~ s{[^/]$}{&/} ) if $newName;
+ return $self->addDirectory( $name, $newName );
+ }
+ else {
+ return _error("$name is neither a file nor a directory");
+ }
+}
+
+sub contents {
+ my ( $self, $member, $newContents ) = @_;
+ return _error('No member name given') unless $member;
+ $member = $self->memberNamed($member) unless ref($member);
+ return undef unless $member;
+ return $member->contents($newContents);
+}
+
+sub writeToFileNamed {
+ my $self = shift;
+ my $fileName = shift; # local FS format
+ foreach my $member ( $self->members() ) {
+ if ( $member->_usesFileNamed($fileName) ) {
+ return _error( "$fileName is needed by member "
+ . $member->fileName()
+ . "; consider using overwrite() or overwriteAs() instead." );
+ }
+ }
+ my ( $status, $fh ) = _newFileHandle( $fileName, 'w' );
+ return _ioError("Can't open $fileName for write") unless $status;
+ my $retval = $self->writeToFileHandle( $fh, 1 );
+ $fh->close();
+ $fh = undef;
+
+ return $retval;
+}
+
+# It is possible to write data to the FH before calling this,
+# perhaps to make a self-extracting archive.
+sub writeToFileHandle {
+ my $self = shift;
+ my $fh = shift;
+ return _error('No filehandle given') unless $fh;
+ return _ioError('filehandle not open') unless $fh->opened();
+
+ my $fhIsSeekable = @_ ? shift: _isSeekable($fh);
+ _binmode($fh);
+
+ # Find out where the current position is.
+ my $offset = $fhIsSeekable ? $fh->tell() : 0;
+ $offset = 0 if $offset < 0;
+
+ foreach my $member ( $self->members() ) {
+ my $retval = $member->_writeToFileHandle( $fh, $fhIsSeekable, $offset );
+ $member->endRead();
+ return $retval if $retval != AZ_OK;
+ $offset += $member->_localHeaderSize() + $member->_writeOffset();
+ $offset +=
+ $member->hasDataDescriptor()
+ ? DATA_DESCRIPTOR_LENGTH + SIGNATURE_LENGTH
+ : 0;
+
+ # changed this so it reflects the last successful position
+ $self->{'writeCentralDirectoryOffset'} = $offset;
+ }
+ return $self->writeCentralDirectory($fh);
+}
+
+# Write zip back to the original file,
+# as safely as possible.
+# Returns AZ_OK if successful.
+sub overwrite {
+ my $self = shift;
+ return $self->overwriteAs( $self->{'fileName'} );
+}
+
+# Write zip to the specified file,
+# as safely as possible.
+# Returns AZ_OK if successful.
+sub overwriteAs {
+ my $self = shift;
+ my $zipName = shift;
+ return _error("no filename in overwriteAs()") unless defined($zipName);
+
+ my ( $fh, $tempName ) = Archive::Zip::tempFile();
+ return _error( "Can't open temp file", $! ) unless $fh;
+
+ ( my $backupName = $zipName ) =~ s{(\.[^.]*)?$}{.zbk};
+
+ my $status = $self->writeToFileHandle($fh);
+ $fh->close();
+ $fh = undef;
+
+ if ( $status != AZ_OK ) {
+ unlink($tempName);
+ _printError("Can't write to $tempName");
+ return $status;
+ }
+
+ my $err;
+
+ # rename the zip
+ if ( -f $zipName && !rename( $zipName, $backupName ) ) {
+ $err = $!;
+ unlink($tempName);
+ return _error( "Can't rename $zipName as $backupName", $err );
+ }
+
+ # move the temp to the original name (possibly copying)
+ unless ( File::Copy::move( $tempName, $zipName ) ) {
+ $err = $!;
+ rename( $backupName, $zipName );
+ unlink($tempName);
+ return _error( "Can't move $tempName to $zipName", $err );
+ }
+
+ # unlink the backup
+ if ( -f $backupName && !unlink($backupName) ) {
+ $err = $!;
+ return _error( "Can't unlink $backupName", $err );
+ }
+
+ return AZ_OK;
+}
+
+# Used only during writing
+sub _writeCentralDirectoryOffset {
+ shift->{'writeCentralDirectoryOffset'};
+}
+
+sub _writeEOCDOffset {
+ shift->{'writeEOCDOffset'};
+}
+
+# Expects to have _writeEOCDOffset() set
+sub _writeEndOfCentralDirectory {
+ my ( $self, $fh ) = @_;
+
+ $fh->print(END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING)
+ or return _ioError('writing EOCD Signature');
+ my $zipfileCommentLength = length( $self->zipfileComment() );
+
+ my $header = pack(
+ END_OF_CENTRAL_DIRECTORY_FORMAT,
+ 0, # {'diskNumber'},
+ 0, # {'diskNumberWithStartOfCentralDirectory'},
+ $self->numberOfMembers(), # {'numberOfCentralDirectoriesOnThisDisk'},
+ $self->numberOfMembers(), # {'numberOfCentralDirectories'},
+ $self->_writeEOCDOffset() - $self->_writeCentralDirectoryOffset(),
+ $self->_writeCentralDirectoryOffset(),
+ $zipfileCommentLength
+ );
+ $fh->print($header)
+ or return _ioError('writing EOCD header');
+ if ($zipfileCommentLength) {
+ $fh->print( $self->zipfileComment() )
+ or return _ioError('writing zipfile comment');
+ }
+ return AZ_OK;
+}
+
+# $offset can be specified to truncate a zip file.
+sub writeCentralDirectory {
+ my ( $self, $fh, $offset ) = @_;
+
+ if ( defined($offset) ) {
+ $self->{'writeCentralDirectoryOffset'} = $offset;
+ $fh->seek( $offset, IO::Seekable::SEEK_SET )
+ or return _ioError('seeking to write central directory');
+ }
+ else {
+ $offset = $self->_writeCentralDirectoryOffset();
+ }
+
+ foreach my $member ( $self->members() ) {
+ my $status = $member->_writeCentralDirectoryFileHeader($fh);
+ return $status if $status != AZ_OK;
+ $offset += $member->_centralDirectoryHeaderSize();
+ $self->{'writeEOCDOffset'} = $offset;
+ }
+ return $self->_writeEndOfCentralDirectory($fh);
+}
+
+sub read {
+ my $self = shift;
+ my $fileName = shift;
+ return _error('No filename given') unless $fileName;
+ my ( $status, $fh ) = _newFileHandle( $fileName, 'r' );
+ return _ioError("opening $fileName for read") unless $status;
+
+ $status = $self->readFromFileHandle( $fh, $fileName );
+ return $status if $status != AZ_OK;
+
+ $fh->close();
+ $self->{'fileName'} = $fileName;
+ return AZ_OK;
+}
+
+sub readFromFileHandle {
+ my $self = shift;
+ my $fh = shift;
+ my $fileName = shift;
+ $fileName = $fh unless defined($fileName);
+ return _error('No filehandle given') unless $fh;
+ return _ioError('filehandle not open') unless $fh->opened();
+
+ _binmode($fh);
+ $self->{'fileName'} = "$fh";
+
+ # TODO: how to support non-seekable zips?
+ return _error('file not seekable')
+ unless _isSeekable($fh);
+
+ $fh->seek( 0, 0 ); # rewind the file
+
+ my $status = $self->_findEndOfCentralDirectory($fh);
+ return $status if $status != AZ_OK;
+
+ my $eocdPosition = $fh->tell();
+
+ $status = $self->_readEndOfCentralDirectory($fh);
+ return $status if $status != AZ_OK;
+
+ $fh->seek( $eocdPosition - $self->centralDirectorySize(),
+ IO::Seekable::SEEK_SET )
+ or return _ioError("Can't seek $fileName");
+
+ # Try to detect garbage at beginning of archives
+ # This should be 0
+ $self->{'eocdOffset'} = $eocdPosition - $self->centralDirectorySize() # here
+ - $self->centralDirectoryOffsetWRTStartingDiskNumber();
+
+ for ( ; ; ) {
+ my $newMember =
+ $self->ZIPMEMBERCLASS->_newFromZipFile( $fh, $fileName,
+ $self->eocdOffset() );
+ my $signature;
+ ( $status, $signature ) = _readSignature( $fh, $fileName );
+ return $status if $status != AZ_OK;
+ last if $signature == END_OF_CENTRAL_DIRECTORY_SIGNATURE;
+ $status = $newMember->_readCentralDirectoryFileHeader();
+ return $status if $status != AZ_OK;
+ $status = $newMember->endRead();
+ return $status if $status != AZ_OK;
+ $newMember->_becomeDirectoryIfNecessary();
+ push( @{ $self->{'members'} }, $newMember );
+ }
+
+ return AZ_OK;
+}
+
+# Read EOCD, starting from position before signature.
+# Return AZ_OK on success.
+sub _readEndOfCentralDirectory {
+ my $self = shift;
+ my $fh = shift;
+
+ # Skip past signature
+ $fh->seek( SIGNATURE_LENGTH, IO::Seekable::SEEK_CUR )
+ or return _ioError("Can't seek past EOCD signature");
+
+ my $header = '';
+ my $bytesRead = $fh->read( $header, END_OF_CENTRAL_DIRECTORY_LENGTH );
+ if ( $bytesRead != END_OF_CENTRAL_DIRECTORY_LENGTH ) {
+ return _ioError("reading end of central directory");
+ }
+
+ my $zipfileCommentLength;
+ (
+ $self->{'diskNumber'},
+ $self->{'diskNumberWithStartOfCentralDirectory'},
+ $self->{'numberOfCentralDirectoriesOnThisDisk'},
+ $self->{'numberOfCentralDirectories'},
+ $self->{'centralDirectorySize'},
+ $self->{'centralDirectoryOffsetWRTStartingDiskNumber'},
+ $zipfileCommentLength
+ ) = unpack( END_OF_CENTRAL_DIRECTORY_FORMAT, $header );
+
+ if ($zipfileCommentLength) {
+ my $zipfileComment = '';
+ $bytesRead = $fh->read( $zipfileComment, $zipfileCommentLength );
+ if ( $bytesRead != $zipfileCommentLength ) {
+ return _ioError("reading zipfile comment");
+ }
+ $self->{'zipfileComment'} = $zipfileComment;
+ }
+
+ return AZ_OK;
+}
+
+# Seek in my file to the end, then read backwards until we find the
+# signature of the central directory record. Leave the file positioned right
+# before the signature. Returns AZ_OK if success.
+sub _findEndOfCentralDirectory {
+ my $self = shift;
+ my $fh = shift;
+ my $data = '';
+ $fh->seek( 0, IO::Seekable::SEEK_END )
+ or return _ioError("seeking to end");
+
+ my $fileLength = $fh->tell();
+ if ( $fileLength < END_OF_CENTRAL_DIRECTORY_LENGTH + 4 ) {
+ return _formatError("file is too short");
+ }
+
+ my $seekOffset = 0;
+ my $pos = -1;
+ for ( ; ; ) {
+ $seekOffset += 512;
+ $seekOffset = $fileLength if ( $seekOffset > $fileLength );
+ $fh->seek( -$seekOffset, IO::Seekable::SEEK_END )
+ or return _ioError("seek failed");
+ my $bytesRead = $fh->read( $data, $seekOffset );
+ if ( $bytesRead != $seekOffset ) {
+ return _ioError("read failed");
+ }
+ $pos = rindex( $data, END_OF_CENTRAL_DIRECTORY_SIGNATURE_STRING );
+ last
+ if ( $pos >= 0
+ or $seekOffset == $fileLength
+ or $seekOffset >= $Archive::Zip::ChunkSize );
+ }
+
+ if ( $pos >= 0 ) {
+ $fh->seek( $pos - $seekOffset, IO::Seekable::SEEK_CUR )
+ or return _ioError("seeking to EOCD");
+ return AZ_OK;
+ }
+ else {
+ return _formatError("can't find EOCD signature");
+ }
+}
+
+# Used to avoid taint problems when chdir'ing.
+# Not intended to increase security in any way; just intended to shut up the -T
+# complaints. If your Cwd module is giving you unreliable returns from cwd()
+# you have bigger problems than this.
+sub _untaintDir {
+ my $dir = shift;
+ $dir =~ m/\A(.+)\z/s;
+ return $1;
+}
+
+sub addTree {
+ my $self = shift;
+ my $root = shift or return _error("root arg missing in call to addTree()");
+ my $dest = shift;
+ $dest = '' unless defined($dest);
+ my $pred = shift || sub { -r };
+ my @files;
+ my $startDir = _untaintDir( cwd() );
+
+ return _error( 'undef returned by _untaintDir on cwd ', cwd() )
+ unless $startDir;
+
+ # This avoids chdir'ing in Find, in a way compatible with older
+ # versions of File::Find.
+ my $wanted = sub {
+ local $main::_ = $File::Find::name;
+ my $dir = _untaintDir($File::Find::dir);
+ chdir($startDir);
+ push( @files, $File::Find::name ) if (&$pred);
+ chdir($dir);
+ };
+
+ File::Find::find( $wanted, $root );
+
+ my $rootZipName = _asZipDirName( $root, 1 ); # with trailing slash
+ my $pattern = $rootZipName eq './' ? '^' : "^\Q$rootZipName\E";
+
+ $dest = _asZipDirName( $dest, 1 ); # with trailing slash
+
+ foreach my $fileName (@files) {
+ my $isDir = -d $fileName;
+
+ # normalize, remove leading ./
+ my $archiveName = _asZipDirName( $fileName, $isDir );
+ if ( $archiveName eq $rootZipName ) { $archiveName = $dest }
+ else { $archiveName =~ s{$pattern}{$dest} }
+ next if $archiveName =~ m{^\.?/?$}; # skip current dir
+ my $member = $isDir
+ ? $self->addDirectory( $fileName, $archiveName )
+ : $self->addFile( $fileName, $archiveName );
+ return _error("add $fileName failed in addTree()") if !$member;
+ }
+ return AZ_OK;
+}
+
+sub addTreeMatching {
+ my $self = shift;
+ my $root = shift
+ or return _error("root arg missing in call to addTreeMatching()");
+ my $dest = shift;
+ $dest = '' unless defined($dest);
+ my $pattern = shift
+ or return _error("pattern missing in call to addTreeMatching()");
+ my $pred = shift;
+ my $matcher =
+ $pred ? sub { m{$pattern} && &$pred } : sub { m{$pattern} && -r };
+ return $self->addTree( $root, $dest, $matcher );
+}
+
+# $zip->extractTree( $root, $dest [, $volume] );
+#
+# $root and $dest are Unix-style.
+# $volume is in local FS format.
+#
+sub extractTree {
+ my $self = shift;
+ my $root = shift; # Zip format
+ $root = '' unless defined($root);
+ my $dest = shift; # Zip format
+ $dest = './' unless defined($dest);
+ my $volume = shift; # optional
+ my $pattern = "^\Q$root";
+ my @members = $self->membersMatching($pattern);
+
+ foreach my $member (@members) {
+ my $fileName = $member->fileName(); # in Unix format
+ $fileName =~ s{$pattern}{$dest}; # in Unix format
+ # convert to platform format:
+ $fileName = Archive::Zip::_asLocalName( $fileName, $volume );
+ my $status = $member->extractToFileNamed($fileName);
+ return $status if $status != AZ_OK;
+ }
+ return AZ_OK;
+}
+
+# $zip->updateMember( $memberOrName, $fileName );
+# Returns (possibly updated) member, if any; undef on errors.
+
+sub updateMember {
+ my $self = shift;
+ my $oldMember = shift;
+ my $fileName = shift;
+
+ if ( !defined($fileName) ) {
+ _error("updateMember(): missing fileName argument");
+ return undef;
+ }
+
+ my @newStat = stat($fileName);
+ if ( !@newStat ) {
+ _ioError("Can't stat $fileName");
+ return undef;
+ }
+
+ my $isDir = -d _;
+
+ my $memberName;
+
+ if ( ref($oldMember) ) {
+ $memberName = $oldMember->fileName();
+ }
+ else {
+ $oldMember = $self->memberNamed( $memberName = $oldMember )
+ || $self->memberNamed( $memberName =
+ _asZipDirName( $oldMember, $isDir ) );
+ }
+
+ unless ( defined($oldMember)
+ && $oldMember->lastModTime() == $newStat[9]
+ && $oldMember->isDirectory() == $isDir
+ && ( $isDir || ( $oldMember->uncompressedSize() == $newStat[7] ) ) )
+ {
+
+ # create the new member
+ my $newMember = $isDir
+ ? $self->ZIPMEMBERCLASS->newDirectoryNamed( $fileName, $memberName )
+ : $self->ZIPMEMBERCLASS->newFromFile( $fileName, $memberName );
+
+ unless ( defined($newMember) ) {
+ _error("creation of member $fileName failed in updateMember()");
+ return undef;
+ }
+
+ # replace old member or append new one
+ if ( defined($oldMember) ) {
+ $self->replaceMember( $oldMember, $newMember );
+ }
+ else { $self->addMember($newMember); }
+
+ return $newMember;
+ }
+
+ return $oldMember;
+}
+
+# $zip->updateTree( $root, [ $dest, [ $pred [, $mirror]]] );
+#
+# This takes the same arguments as addTree, but first checks to see
+# whether the file or directory already exists in the zip file.
+#
+# If the fourth argument $mirror is true, then delete all my members
+# if corresponding files weren't found.
+
+sub updateTree {
+ my $self = shift;
+ my $root = shift
+ or return _error("root arg missing in call to updateTree()");
+ my $dest = shift;
+ $dest = '' unless defined($dest);
+ $dest = _asZipDirName( $dest, 1 );
+ my $pred = shift || sub { -r };
+ my $mirror = shift;
+
+ my $rootZipName = _asZipDirName( $root, 1 ); # with trailing slash
+ my $pattern = $rootZipName eq './' ? '^' : "^\Q$rootZipName\E";
+
+ my @files;
+ my $startDir = _untaintDir( cwd() );
+
+ return _error( 'undef returned by _untaintDir on cwd ', cwd() )
+ unless $startDir;
+
+ # This avoids chdir'ing in Find, in a way compatible with older
+ # versions of File::Find.
+ my $wanted = sub {
+ local $main::_ = $File::Find::name;
+ my $dir = _untaintDir($File::Find::dir);
+ chdir($startDir);
+ push( @files, $File::Find::name ) if (&$pred);
+ chdir($dir);
+ };
+
+ File::Find::find( $wanted, $root );
+
+ # Now @files has all the files that I could potentially be adding to
+ # the zip. Only add the ones that are necessary.
+ # For each file (updated or not), add its member name to @done.
+ my %done;
+ foreach my $fileName (@files) {
+ my @newStat = stat($fileName);
+ my $isDir = -d _;
+
+ # normalize, remove leading ./
+ my $memberName = _asZipDirName( $fileName, $isDir );
+ if ( $memberName eq $rootZipName ) { $memberName = $dest }
+ else { $memberName =~ s{$pattern}{$dest} }
+ next if $memberName =~ m{^\.?/?$}; # skip current dir
+
+ $done{$memberName} = 1;
+ my $changedMember = $self->updateMember( $memberName, $fileName );
+ return _error("updateTree failed to update $fileName")
+ unless ref($changedMember);
+ }
+
+ # @done now has the archive names corresponding to all the found files.
+ # If we're mirroring, delete all those members that aren't in @done.
+ if ($mirror) {
+ foreach my $member ( $self->members() ) {
+ $self->removeMember($member)
+ unless $done{ $member->fileName() };
+ }
+ }
+
+ return AZ_OK;
+}
+
+1;
Propchange: trunk/server/CPAN/Archive/Zip/Archive.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/CPAN/Archive/Zip/Archive.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/CPAN/Archive/Zip/Archive.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm (added)
+++ trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm Thu Dec 21 14:28:39 2006
@@ -1,0 +1,131 @@
+package Archive::Zip::BufferedFileHandle;
+
+# File handle that uses a string internally and can seek
+# This is given as a demo for getting a zip file written
+# to a string.
+# I probably should just use IO::Scalar instead.
+# Ned Konz, March 2000
+
+use strict;
+use IO::File;
+use Carp;
+
+use vars qw{$VERSION};
+
+BEGIN {
+ $VERSION = '1.18';
+ $VERSION = eval $VERSION;
+}
+
+sub new {
+ my $class = shift || __PACKAGE__;
+ $class = ref($class) || $class;
+ my $self = bless(
+ {
+ content => '',
+ position => 0,
+ size => 0
+ },
+ $class
+ );
+ return $self;
+}
+
+# Utility method to read entire file
+sub readFromFile {
+ my $self = shift;
+ my $fileName = shift;
+ my $fh = IO::File->new( $fileName, "r" );
+ CORE::binmode($fh);
+ if ( !$fh ) {
+ Carp::carp("Can't open $fileName: $!\n");
+ return undef;
+ }
+ local $/ = undef;
+ $self->{content} = <$fh>;
+ $self->{size} = length( $self->{content} );
+ return $self;
+}
+
+sub contents {
+ my $self = shift;
+ if (@_) {
+ $self->{content} = shift;
+ $self->{size} = length( $self->{content} );
+ }
+ return $self->{content};
+}
+
+sub binmode { 1 }
+
+sub close { 1 }
+
+sub opened { 1 }
+
+sub eof {
+ my $self = shift;
+ return $self->{position} >= $self->{size};
+}
+
+sub seek {
+ my $self = shift;
+ my $pos = shift;
+ my $whence = shift;
+
+ # SEEK_SET
+ if ( $whence == 0 ) { $self->{position} = $pos; }
+
+ # SEEK_CUR
+ elsif ( $whence == 1 ) { $self->{position} += $pos; }
+
+ # SEEK_END
+ elsif ( $whence == 2 ) { $self->{position} = $self->{size} + $pos; }
+ else { return 0; }
+
+ return 1;
+}
+
+sub tell { return shift->{position}; }
+
+# Copy my data to given buffer
+sub read {
+ my $self = shift;
+ my $buf = \( $_[0] );
+ shift;
+ my $len = shift;
+ my $offset = shift || 0;
+
+ $$buf = '' if not defined($$buf);
+ my $bytesRead =
+ ( $self->{position} + $len > $self->{size} )
+ ? ( $self->{size} - $self->{position} )
+ : $len;
+ substr( $$buf, $offset, $bytesRead ) =
+ substr( $self->{content}, $self->{position}, $bytesRead );
+ $self->{position} += $bytesRead;
+ return $bytesRead;
+}
+
+# Copy given buffer to me
+sub write {
+ my $self = shift;
+ my $buf = \( $_[0] );
+ shift;
+ my $len = shift;
+ my $offset = shift || 0;
+
+ $$buf = '' if not defined($$buf);
+ my $bufLen = length($$buf);
+ my $bytesWritten =
+ ( $offset + $len > $bufLen )
+ ? $bufLen - $offset
+ : $len;
+ substr( $self->{content}, $self->{position}, $bytesWritten ) =
+ substr( $$buf, $offset, $bytesWritten );
+ $self->{size} = length( $self->{content} );
+ return $bytesWritten;
+}
+
+sub clearerr() { 1 }
+
+1;
Propchange: trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/CPAN/Archive/Zip/BufferedFileHandle.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: trunk/server/CPAN/Archive/Zip/DirectoryMember.pm
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip/DirectoryMember.pm?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip/DirectoryMember.pm (added)
+++ trunk/server/CPAN/Archive/Zip/DirectoryMember.pm Thu Dec 21 14:28:39 2006
@@ -1,0 +1,82 @@
+package Archive::Zip::DirectoryMember;
+
+use strict;
+use File::Path;
+
+use vars qw( $VERSION @ISA );
+
+BEGIN {
+ $VERSION = '1.18';
+ @ISA = qw( Archive::Zip::Member );
+}
+
+use Archive::Zip qw(
+ :ERROR_CODES
+ :UTILITY_METHODS
+);
+
+sub _newNamed {
+ my $class = shift;
+ my $fileName = shift; # FS name
+ my $newName = shift; # Zip name
+ $newName = _asZipDirName($fileName) unless $newName;
+ my $self = $class->new(@_);
+ $self->{'externalFileName'} = $fileName;
+ $self->fileName($newName);
+
+ if ( -e $fileName ) {
+
+ # -e does NOT do a full stat, so we need to do one now
+ if ( -d _ ) {
+ my @stat = stat(_);
+ $self->unixFileAttributes( $stat[2] );
+ my $mod_t = $stat[9];
+ if ( $^O eq 'MSWin32' and !$mod_t ) {
+ $mod_t = time();
+ }
+ $self->setLastModFileDateTimeFromUnix($mod_t);
+
+ }
+ else { # hmm.. trying to add a non-directory?
+ _error( $fileName, ' exists but is not a directory' );
+ return undef;
+ }
+ }
+ else {
+ $self->unixFileAttributes( $self->DEFAULT_DIRECTORY_PERMISSIONS );
+ $self->setLastModFileDateTimeFromUnix( time() );
+ }
+ return $self;
+}
+
+sub externalFileName {
+ shift->{'externalFileName'};
+}
+
+sub isDirectory {
+ return 1;
+}
+
+sub extractToFileNamed {
+ my $self = shift;
+ my $name = shift; # local FS name
+ my $attribs = $self->unixFileAttributes() & 07777;
+ mkpath( $name, 0, $attribs ); # croaks on error
+ utime( $self->lastModTime(), $self->lastModTime(), $name );
+ return AZ_OK;
+}
+
+sub fileName {
+ my $self = shift;
+ my $newName = shift;
+ $newName =~ s{/?$}{/} if defined($newName);
+ return $self->SUPER::fileName($newName);
+}
+
+# So people don't get too confused. This way it looks like the problem
+# is in their code...
+sub contents {
+ return wantarray ? ( undef, AZ_OK ) : undef;
+}
+
+1;
Propchange: trunk/server/CPAN/Archive/Zip/DirectoryMember.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/CPAN/Archive/Zip/DirectoryMember.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/CPAN/Archive/Zip/DirectoryMember.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: trunk/server/CPAN/Archive/Zip/FAQ.pod
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip/FAQ.pod?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip/FAQ.pod (added)
+++ trunk/server/CPAN/Archive/Zip/FAQ.pod Thu Dec 21 14:28:39 2006
@@ -1,0 +1,467 @@
+
+=head1 NAME
+
+
+Archive::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip
+
+=head1 DESCRIPTION
+
+
+It seems that I keep answering the same questions over and over again. I
+assume that this is because my documentation is deficient, rather than that
+people don't read the documentation.
+
+
+So this FAQ is an attempt to cut down on the number of personal answers I have
+to give. At least I can now say "You I<did> read the FAQ, right?".
+
+
+The questions are not in any particular order. The answers assume the current
+version of Archive::Zip; some of the answers depend on newly added/fixed
+functionality.
+
+=head1 Install problems on RedHat 8 or 9 with Perl 5.8.0
+
+
+B<Q:> Archive::Zip won't install on my RedHat 9 system! It's broke!
+
+
+B<A:> This has become something of a FAQ.
+Basically, RedHat broke some versions of Perl by setting LANG to UTF8.
+They apparently have a fixed version out as an update.
+
+You might try running CPAN or creating your Makefile after exporting the LANG
+environment variable as
+
+C<LANG=C>
+
+L<https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=87682>
+
+
+=head1 Why is my zip file so big?
+
+
+B<Q:> My zip file is actually bigger than what I stored in it! Why?
+
+
+B<A:> Some things to make sure of:
+
+=over 4
+
+=item Make sure that you are requesting COMPRESSION_DEFLATED if you are storing strings.
+
+
+
+
+$member->desiredCompressionMethod( COMPRESSION_DEFLATED );
+
+
+=item Don't make lots of little files if you can help it.
+
+
+
+Since zip computes the compression tables for each member, small
+members without much entropy won't compress well. Instead, if you've
+got lots of repeated strings in your data, try to combine them into
+one big member.
+
+
+=item Make sure that you are requesting COMPRESSION_STORED if you are storing things that are already compressed.
+
+
+
+If you're storing a .zip, .jpg, .mp3, or other compressed file in a zip,
+then don't compress them again. They'll get bigger.
+
+=back
+
+=head1 Sample code?
+
+
+B<Q:> Can you send me code to do (whatever)?
+
+
+B<A:> Have you looked in the C<examples/> directory yet? It contains:
+
+=over 4
+
+=item examples/calcSizes.pl -- How to find out how big a Zip file will be before writing it
+
+
+
+=item examples/copy.pl -- Copies one Zip file to another
+
+
+
+=item examples/extract.pl -- extract file(s) from a Zip
+
+
+
+=item examples/mailZip.pl -- make and mail a zip file
+
+
+
+=item examples/mfh.pl -- demo for use of MockFileHandle
+
+
+
+=item examples/readScalar.pl -- shows how to use IO::Scalar as the source of a Zip read
+
+
+
+=item examples/selfex.pl -- a brief example of a self-extracting Zip
+
+
+
+=item examples/unzipAll.pl -- uses Archive::Zip::Tree to unzip an entire Zip
+
+
+
+=item examples/updateZip.pl -- shows how to read/modify/write a Zip
+
+
+
+=item examples/updateTree.pl -- shows how to update a Zip in place
+
+
+
+=item examples/writeScalar.pl -- shows how to use IO::Scalar as the destination of a Zip write
+
+
+
+=item examples/writeScalar2.pl -- shows how to use IO::String as the destination of a Zip write
+
+
+
+=item examples/zip.pl -- Constructs a Zip file
+
+
+
+=item examples/zipcheck.pl -- One way to check a Zip file for validity
+
+
+
+=item examples/zipinfo.pl -- Prints out information about a Zip archive file
+
+
+
+=item examples/zipGrep.pl -- Searches for text in Zip files
+
+
+
+=item examples/ziptest.pl -- Lists a Zip file and checks member CRCs
+
+
+
+=item examples/ziprecent.pl -- Puts recent files into a zipfile
+
+
+
+=item examples/ziptest.pl -- Another way to check a Zip file for validity
+
+
+
+=back
+
+=head1 Can't Read/modify/write same Zip file
+
+
+B<Q:> Why can't I open a Zip file, add a member, and write it back? I get an
+error message when I try.
+
+
+B<A:> Because Archive::Zip doesn't (and can't, generally) read file contents into memory,
+the original Zip file is required to stay around until the writing of the new
+file is completed.
+
+
+The best way to do this is to write the Zip to a temporary file and then
+rename the temporary file to have the old name (possibly after deleting the
+old one).
+
+
+Archive::Zip v1.02 added the archive methods C<overwrite()> and
+C<overwriteAs()> to do this simply and carefully.
+
+
+See C<examples/updateZip.pl> for an example of this technique.
+
+=head1 File creation time not set
+
+
+B<Q:> Upon extracting files, I see that their modification (and access) times are
+set to the time in the Zip archive. However, their creation time is not set to
+the same time. Why?
+
+
+B<A:> Mostly because Perl doesn't give cross-platform access to I<creation time>.
+Indeed, many systems (like Unix) don't support such a concept.
+However, if yours does, you can easily set it. Get the modification time from
+the member using C<lastModTime()>.
+
+=head1 Can't use Archive::Zip on gzip files
+
+
+B<Q:> Can I use Archive::Zip to extract Unix gzip files?
+
+
+B<A:> No.
+
+
+There is a distinction between Unix gzip files, and Zip archives that
+also can use the gzip compression.
+
+
+Depending on the format of the gzip file, you can use L<Compress::Zlib>, or
+L<Archive::Tar> to decompress it (and de-archive it in the case of Tar files).
+
+
+You can unzip PKZIP/WinZip/etc/ archives using Archive::Zip (that's what
+it's for) as long as any compressed members are compressed using
+Deflate compression.
+
+=head1 Add a directory/tree to a Zip
+
+
+B<Q:> How can I add a directory (or tree) full of files to a Zip?
+
+
+B<A:> You can use the Archive::Zip::addTree*() methods:
+
+ use Archive::Zip;
+ my $zip = Archive::Zip->new();
+ # add all readable files and directories below . as xyz/*
+ $zip->addTree( '.', 'xyz' );
+ # add all readable plain files below /abc as def/*
+ $zip->addTree( '/abc', 'def', sub { -f && -r } );
+ # add all .c files below /tmp as stuff/*
+ $zip->addTreeMatching( '/tmp', 'stuff', '\.c$' );
+ # add all .o files below /tmp as stuff/* if they aren't writable
+ $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { ! -w } );
+ # add all .so files below /tmp that are smaller than 200 bytes as stuff/*
+ $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { -s < 200 } );
+ # and write them into a file
+ $zip->writeToFileNamed('xxx.zip');
+
+=head1 Extract a directory/tree
+
+
+B<Q:> How can I extract some (or all) files from a Zip into a different
+directory?
+
+
+B<A:> You can use the Archive::Zip::extractTree() method:
+??? ||
+
+
+ # now extract the same files into /tmpx
+ $zip->extractTree( 'stuff', '/tmpx' );
+
+=head1 Update a directory/tree
+
+
+B<Q:> How can I update a Zip from a directory tree, adding or replacing only
+the newer files?
+
+
+B<A:> You can use the Archive::Zip::updateTree() method that was added in version 1.09.
+
+=head1 Zip times might be off by 1 second
+
+
+B<Q:> It bothers me greatly that my file times are wrong by one second about half
+the time. Why don't you do something about it?
+
+
+B<A:> Get over it. This is a result of the Zip format storing times in DOS
+format, which has a resolution of only two seconds.
+
+=head1 Zip times don't include time zone information
+
+
+B<Q:> My file times don't respect time zones. What gives?
+
+
+B<A:> If this is important to you, please submit patches to read the various
+Extra Fields that encode times with time zones. I'm just using the DOS
+Date/Time, which doesn't have a time zone.
+
+=head1 How do I make a self-extracting Zip
+
+
+B<Q:> I want to make a self-extracting Zip file. Can I do this?
+
+
+B<A:> Yes. You can write a self-extracting archive stub (that is, a version of
+unzip) to the output filehandle that you pass to writeToFileHandle(). See
+examples/selfex.pl for how to write a self-extracting archive.
+
+
+However, you should understand that this will only work on one kind of
+platform (the one for which the stub was compiled).
+
+=head1 How can I deal with Zips with prepended garbage (i.e. from Sircam)
+
+
+B<Q:> How can I tell if a Zip has been damaged by adding garbage to the
+beginning or inside the file?
+
+
+B<A:> I added code for this for the Amavis virus scanner. You can query archives
+for their 'eocdOffset' property, which should be 0:
+
+
+ if ($zip->eocdOffset > 0)
+ { warn($zip->eocdOffset . " bytes of garbage at beginning or within Zip") }
+
+
+When members are extracted, this offset will be used to adjust the start of
+the member if necessary.
+
+=head1 Can't extract Shrunk files
+
+
+B<Q:> I'm trying to extract a file out of a Zip produced by PKZIP, and keep
+getting this error message:
+
+
+ error: Unsupported compression combination: read 6, write 0
+
+
+B<A:> You can't uncompress this archive member. Archive::Zip only supports uncompressed
+members, and compressed members that are compressed using the compression
+supported by Compress::Zlib. That means only Deflated and Stored members.
+
+
+Your file is compressed using the Shrink format, which isn't supported by
+Compress::Zlib.
+
+
+You could, perhaps, use a command-line UnZip program (like the Info-Zip
+one) to extract this.
+
+=head1 Can't do decryption
+
+
+B<Q:> How do I decrypt encrypted Zip members?
+
+
+B<A:> With some other program or library. Archive::Zip doesn't support decryption,
+and probably never will (unless I<you> write it).
+
+=head1 How to test file integrity?
+
+
+B<Q:> How can Archive::Zip can test the validity of a Zip file?
+
+
+B<A:> If you try to decompress the file, the gzip streams will report errors
+if you have garbage. Most of the time.
+
+If you try to open the file and a central directory structure can't be
+found, an error will be reported.
+
+When a file is being read, if we can't find a proper PK.. signature in
+the right places we report a format error.
+
+If there is added garbage at the beginning of a Zip file (as inserted
+by some viruses), you can find out about it, but Archive::Zip will ignore it,
+and you can still use the archive. When it gets written back out the
+added stuff will be gone.
+
+
+There are two ready-to-use utilities in the examples directory that can
+be used to test file integrity, or that you can use as examples
+for your own code:
+
+=over 4
+
+=item examples/zipcheck.pl shows how to use an attempted extraction to test a file.
+
+
+
+=item examples/ziptest.pl shows how to test CRCs in a file.
+
+
+
+=back
+
+=head1 Duplicate files in Zip?
+
+
+B<Q:> Archive::Zip let me put the same file in my Zip twice! Why don't you prevent this?
+
+
+B<A:> As far as I can tell, this is not disallowed by the Zip spec. If you
+think it's a bad idea, check for it yourself:
+
+
+ $zip->addFile($someFile, $someName) unless $zip->memberNamed($someName);
+
+
+I can even imagine cases where this might be useful (for instance, multiple
+versions of files).
+
+=head1 File ownership/permissions/ACLS/etc
+
+
+B<Q:> Why doesn't Archive::Zip deal with file ownership, ACLs, etc.?
+
+
+B<A:> There is no standard way to represent these in the Zip file format. If
+you want to send me code to properly handle the various extra fields that
+have been used to represent these through the years, I'll look at it.
+
+=head1 I can't compile but ActiveState only has an old version of Archive::Zip
+
+
+B<Q:> I've only installed modules using ActiveState's PPM program and
+repository. But they have a much older version of Archive::Zip than is in CPAN. Will
+you send me a newer PPM?
+
+
+B<A:> Probably not, unless I get lots of extra time. But there's no reason you
+can't install the version from CPAN. Archive::Zip is pure Perl, so all you need is
+NMAKE, which you can get for free from Microsoft (see the FAQ in the
+ActiveState documentation for details on how to install CPAN modules).
+
+=head1 My JPEGs (or MP3's) don't compress when I put them into Zips!
+
+
+B<Q:> How come my JPEGs and MP3's don't compress much when I put them into Zips?
+
+
+B<A:> Because they're already compressed.
+
+=head1 Under Windows, things lock up/get damaged
+
+
+B<Q:> I'm using Windows. When I try to use Archive::Zip, my machine locks up/makes
+funny sounds/displays a BSOD/corrupts data. How can I fix this?
+
+
+B<A:> First, try the newest version of Compress::Zlib. I know of
+Windows-related problems prior to v1.14 of that library.
+
+
+If that doesn't get rid of the problem, fix your computer or get rid of
+Windows.
+
+=head1 Zip contents in a scalar
+
+
+B<Q:> I want to read a Zip file from (or write one to) a scalar variable instead
+of a file. How can I do this?
+
+
+B<A:> Use C<IO::Scalar> and the C<readFromFileHandle()> and
+C<writeToFileHandle()> methods.
+See C<examples/readScalar.pl> and C<examples/writeScalar.pl>.
+
+=head1 Reading from streams
+
+
+B<Q:> How do I read from a stream (like for the Info-Zip C<funzip> program)?
+
+
+B<A:> This isn't currently supported, though writing to a stream is.
Added: trunk/server/CPAN/Archive/Zip/FileMember.pm
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip/FileMember.pm?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip/FileMember.pm (added)
+++ trunk/server/CPAN/Archive/Zip/FileMember.pm Thu Dec 21 14:28:39 2006
@@ -1,0 +1,64 @@
+package Archive::Zip::FileMember;
+
+use strict;
+use vars qw( $VERSION @ISA );
+
+BEGIN {
+ $VERSION = '1.18';
+ @ISA = qw ( Archive::Zip::Member );
+}
+
+use Archive::Zip qw(
+ :UTILITY_METHODS
+);
+
+sub externalFileName {
+ shift->{'externalFileName'};
+}
+
+# Return true if I depend on the named file
+sub _usesFileNamed {
+ my $self = shift;
+ my $fileName = shift;
+ my $xfn = $self->externalFileName();
+ return undef if ref($xfn);
+ return $xfn eq $fileName;
+}
+
+sub fh {
+ my $self = shift;
+ $self->_openFile()
+ if !defined( $self->{'fh'} ) || !$self->{'fh'}->opened();
+ return $self->{'fh'};
+}
+
+# opens my file handle from my file name
+sub _openFile {
+ my $self = shift;
+ my ( $status, $fh ) = _newFileHandle( $self->externalFileName(), 'r' );
+ if ( !$status ) {
+ _ioError( "Can't open", $self->externalFileName() );
+ return undef;
+ }
+ $self->{'fh'} = $fh;
+ _binmode($fh);
+ return $fh;
+}
+
+# Make sure I close my file handle
+sub endRead {
+ my $self = shift;
+ undef $self->{'fh'}; # _closeFile();
+ return $self->SUPER::endRead(@_);
+}
+
+sub _become {
+ my $self = shift;
+ my $newClass = shift;
+ return $self if ref($self) eq $newClass;
+ delete( $self->{'externalFileName'} );
+ delete( $self->{'fh'} );
+ return $self->SUPER::_become($newClass);
+}
+
+1;
Propchange: trunk/server/CPAN/Archive/Zip/FileMember.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/CPAN/Archive/Zip/FileMember.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/CPAN/Archive/Zip/FileMember.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: trunk/server/CPAN/Archive/Zip/Member.pm
URL: http://svn.slimdevices.com/trunk/server/CPAN/Archive/Zip/Member.pm?rev=11021&view=auto
==============================================================================
--- trunk/server/CPAN/Archive/Zip/Member.pm (added)
+++ trunk/server/CPAN/Archive/Zip/Member.pm Thu Dec 21 14:28:39 2006
@@ -1,0 +1,950 @@
+package Archive::Zip::Member;
+
+# A generic membet of an archive
+
+use strict;
+use vars qw( $VERSION @ISA );
+
+BEGIN {
+ $VERSION = '1.18';
+ @ISA = qw( Archive::Zip );
+}
+
+use Archive::Zip qw(
+ :CONSTANTS
+ :MISC_CONSTANTS
+ :ERROR_CODES
+ :PKZIP_CONSTANTS
+ :UTILITY_METHODS
+);
+
+use Time::Local ();
+use Compress::Zlib qw( Z_OK Z_STREAM_END MAX_WBITS );
+use File::Path;
+use File::Basename;
+
+use constant ZIPFILEMEMBERCLASS => 'Archive::Zip::ZipFileMember';
+use constant NEWFILEMEMBERCLASS => 'Archive::Zip::NewFileMember';
+use constant STRINGMEMBERCLASS => 'Archive::Zip::StringMember';
+use constant DIRECTORYMEMBERCLASS => 'Archive::Zip::DirectoryMember';
+
+# Unix perms for default creation of files/dirs.
+use constant DEFAULT_DIRECTORY_PERMISSIONS => 040755;
+use constant DEFAULT_FILE_PERMISSIONS => 0100666;
+use constant DIRECTORY_ATTRIB => 040000;
+use constant FILE_ATTRIB => 0100000;
+
+# Returns self if successful, else undef
+# Assumes that fh is positioned at beginning of central directory file header.
+# Leaves fh positioned immediately after file header or EOCD signature.
+sub _newFromZipFile {
+ my $class = shift;
+ my $self = $class->ZIPFILEMEMBERCLASS->_newFromZipFile(@_);
+ return $self;
+}
+
+sub newFromString {
+ my $class = shift;
+ my $self = $class->STRINGMEMBERCLASS->_newFromString(@_);
+ return $self;
+}
+
+sub newFromFile {
+ my $class = shift;
+ my $self = $class->NEWFILEMEMBERCLASS->_newFromFileNamed(@_);
+ return $self;
+}
+
+sub newDirectoryNamed {
+ my $class = shift;
+ my $self = $class->DIRECTORYMEMBERCLASS->_newNamed(@_);
+ return $self;
+}
+
+sub new {
+ my $class = shift;
+ my $self = {
+ 'lastModFileDateTime' => 0,
+ 'fileAttributeFormat' => FA_UNIX,
+ 'versionMadeBy' => 20,
+ 'versionNeededToExtract' => 20,
+ 'bitFlag' => 0,
+ 'compressionMethod' => COMPRESSION_STORED,
+ 'desiredCompressionMethod' => COMPRESSION_STORED,
+ 'desiredCompressionLevel' => COMPRESSION_LEVEL_NONE,
+ 'internalFileAttributes' => 0,
+ 'externalFileAttributes' => 0, # set later
+ 'fileName' => '',
+ 'cdExtraField' => '',
+ 'localExtraField' => '',
+ 'fileComment' => '',
+ 'crc32' => 0,
+ 'compressedSize' => 0,
+ 'uncompressedSize' => 0,
+ @_
+ };
+