home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Zip.pod < prev    next >
Encoding:
Text File  |  2003-11-27  |  40.0 KB  |  1,596 lines

  1.  
  2. =head1 NAME
  3.  
  4.  
  5. Archive::Zip - Provide an interface to ZIP archive files.
  6.  
  7. =head1 SYNOPSIS
  8.  
  9.  
  10.    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
  11.    my $zip = Archive::Zip->new();
  12.    my $member = $zip->addDirectory( 'dirname/' );
  13.    $member = $zip->addString( 'This is a test', 'stringMember.txt' );
  14.    $member->desiredCompressionMethod( COMPRESSION_DEFLATED );
  15.    $member = $zip->addFile( 'xyz.pl', 'AnotherName.pl' );
  16.    die 'write error' unless $zip->writeToFileNamed( 'someZip.zip' ) == AZ_OK;
  17.    $zip = Archive::Zip->new();
  18.    die 'read error' unless $zip->read( 'someZip.zip' ) == AZ_OK;
  19.    $member = $zip->memberNamed( 'stringMember.txt' );
  20.    $member->desiredCompressionMethod( COMPRESSION_STORED );
  21.    die 'write error' unless $zip->writeToFileNamed( 'someOtherZip.zip' ) == AZ_OK;
  22.  
  23. =head1 DESCRIPTION
  24.  
  25.  
  26. The Archive::Zip module allows a Perl program to create, manipulate, read,
  27. and write Zip archive files. Zip archives can be created, or you can read
  28. from existing zip files. Once created, they can be written to files, streams,
  29. or strings. Members can be added, removed, extracted, replaced, rearranged,
  30. and enumerated. They can also be renamed or have their dates, comments, or
  31. other attributes queried or modified. Their data can be compressed or
  32. uncompressed as needed. Members can be created from members in existing Zip
  33. files, or from existing directories, files, or strings. This module uses the
  34. L<Compress::Zlib|Compress::Zlib> library to read and write the compressed
  35. streams inside the files.
  36.  
  37. =head1 FILE NAMING
  38.  
  39.  
  40. Regardless of what your local file system uses for file naming, names in a
  41. Zip file are in Unix format (I<forward> slashes (/) separating directory
  42. names, etc.).
  43. C<Archive::Zip> tries to be consistent with file naming
  44. conventions, and will
  45. translate back and forth between native and Zip file names.
  46. However, it can't guess which format names are in. So two rules control what
  47. kind of file name you must pass various routines:
  48.  
  49. =over 4
  50.  
  51. =item Names of files are in local format.
  52.  
  53.  
  54.  
  55. C<File::Spec> and C<File::Basename> are used for various file
  56. operations. When you're referring to a file on your system, use its
  57. file naming conventions.
  58.  
  59. =item Names of archive members are in Unix format.
  60.  
  61.  
  62.  
  63. This applies to every method that refers to an archive member, or
  64. provides a name for new archive members. The C<extract()> methods
  65. that can take one or two names will convert from local to zip names
  66. if you call them with a single name.
  67.  
  68. =back
  69.  
  70. =head1 OBJECT MODEL
  71.  
  72.  
  73. =head2 Overview
  74.  
  75.  
  76. Archive::Zip::Archive objects are what you ordinarily deal with.
  77. These maintain the structure of a zip file, without necessarily
  78. holding data. When a zip is read from a disk file, the (possibly
  79. compressed) data still lives in the file, not in memory. Archive
  80. members hold information about the individual members, but not
  81. (usually) the actual member data. When the zip is written to a
  82. (different) file, the member data is compressed or copied as needed.
  83. It is possible to make archive members whose data is held in a string
  84. in memory, but this is not done when a zip file is read. Directory
  85. members don't have any data.
  86.  
  87. =head2 Inheritance
  88.  
  89.  
  90.   Exporter
  91.    Archive::Zip                            Common base class, has defs.
  92.        Archive::Zip::Archive               A Zip archive.
  93.        Archive::Zip::Member                Abstract superclass for all members.
  94.            Archive::Zip::StringMember      Member made from a string
  95.            Archive::Zip::FileMember        Member made from an external file
  96.                Archive::Zip::ZipFileMember Member that lives in a zip file
  97.                Archive::Zip::NewFileMember Member whose data is in a file
  98.            Archive::Zip::DirectoryMember   Member that is a directory
  99.  
  100. =head1 EXPORTS
  101.  
  102.  
  103. =over 4
  104.  
  105. =item :CONSTANTS
  106.  
  107.  
  108.  
  109. Exports the following constants: FA_MSDOS FA_UNIX GPBF_ENCRYPTED_MASK
  110. GPBF_DEFLATING_COMPRESSION_MASK GPBF_HAS_DATA_DESCRIPTOR_MASK
  111. COMPRESSION_STORED COMPRESSION_DEFLATED IFA_TEXT_FILE_MASK
  112. IFA_TEXT_FILE IFA_BINARY_FILE COMPRESSION_LEVEL_NONE
  113. COMPRESSION_LEVEL_DEFAULT COMPRESSION_LEVEL_FASTEST
  114. COMPRESSION_LEVEL_BEST_COMPRESSION
  115.  
  116. =item :MISC_CONSTANTS
  117.  
  118.  
  119.  
  120. Exports the following constants (only necessary for extending the
  121. module): FA_AMIGA FA_VAX_VMS FA_VM_CMS FA_ATARI_ST FA_OS2_HPFS
  122. FA_MACINTOSH FA_Z_SYSTEM FA_CPM FA_WINDOWS_NTFS
  123. GPBF_IMPLODING_8K_SLIDING_DICTIONARY_MASK
  124. GPBF_IMPLODING_3_SHANNON_FANO_TREES_MASK
  125. GPBF_IS_COMPRESSED_PATCHED_DATA_MASK COMPRESSION_SHRUNK
  126. DEFLATING_COMPRESSION_NORMAL DEFLATING_COMPRESSION_MAXIMUM
  127. DEFLATING_COMPRESSION_FAST DEFLATING_COMPRESSION_SUPER_FAST
  128. COMPRESSION_REDUCED_1 COMPRESSION_REDUCED_2 COMPRESSION_REDUCED_3
  129. COMPRESSION_REDUCED_4 COMPRESSION_IMPLODED COMPRESSION_TOKENIZED
  130. COMPRESSION_DEFLATED_ENHANCED
  131. COMPRESSION_PKWARE_DATA_COMPRESSION_LIBRARY_IMPLODED
  132.  
  133. =item :ERROR_CODES
  134.  
  135.  
  136.  
  137. Explained below. Returned from most methods. AZ_OK AZ_STREAM_END
  138. AZ_ERROR AZ_FORMAT_ERROR AZ_IO_ERROR
  139.  
  140. =back
  141.  
  142. =head1 ERROR CODES
  143.  
  144.  
  145. Many of the methods in Archive::Zip return error codes. These are implemented
  146. as inline subroutines, using the C<use constant> pragma. They can be imported
  147. into your namespace using the C<:ERROR_CODES> tag:
  148.  
  149.   use Archive::Zip qw( :ERROR_CODES );
  150.   ...
  151.   die "whoops!" unless $zip->read( 'myfile.zip' ) == AZ_OK;
  152.  
  153. =over 4
  154.  
  155. =item AZ_OK (0)
  156.  
  157.  
  158.  
  159. Everything is fine.
  160.  
  161. =item AZ_STREAM_END (1)
  162.  
  163.  
  164.  
  165. The read stream (or central directory) ended normally.
  166.  
  167. =item AZ_ERROR (2)
  168.  
  169.  
  170.  
  171. There was some generic kind of error.
  172.  
  173. =item AZ_FORMAT_ERROR (3)
  174.  
  175.  
  176.  
  177. There is a format error in a ZIP file being read.
  178.  
  179. =item AZ_IO_ERROR (4)
  180.  
  181.  
  182.  
  183. There was an IO error.
  184.  
  185. =back
  186.  
  187. =head1 COMPRESSION
  188.  
  189.  
  190. Archive::Zip allows each member of a ZIP file to be compressed (using the
  191. Deflate algorithm) or uncompressed. Other compression algorithms that some
  192. versions of ZIP have been able to produce are not supported. Each member has
  193. two compression methods: the one it's stored as (this is always
  194. COMPRESSION_STORED for string and external file members), and the one you
  195. desire for the member in the zip file. These can be different, of course, so
  196. you can make a zip member that is not compressed out of one that is, and vice
  197. versa. You can inquire about the current compression and set the desired
  198. compression method:
  199.  
  200.   my $member = $zip->memberNamed( 'xyz.txt' );
  201.   $member->compressionMethod();    # return current compression
  202.   # set to read uncompressed
  203.   $member->desiredCompressionMethod( COMPRESSION_STORED );
  204.   # set to read compressed
  205.   $member->desiredCompressionMethod( COMPRESSION_DEFLATED );
  206.  
  207. There are two different compression methods:
  208.  
  209. =over 4
  210.  
  211. =item COMPRESSION_STORED
  212.  
  213.  
  214.  
  215. file is stored (no compression)
  216.  
  217. =item COMPRESSION_DEFLATED
  218.  
  219.  
  220.  
  221. file is Deflated
  222.  
  223. =back
  224.  
  225. =head2 Compression Levels
  226.  
  227.  
  228. If a member's desiredCompressionMethod is COMPRESSION_DEFLATED, you
  229. can choose different compression levels. This choice may affect the
  230. speed of compression and decompression, as well as the size of the
  231. compressed member data.
  232.  
  233.   $member->desiredCompressionLevel( 9 );
  234.  
  235. The levels given can be:
  236.  
  237. =over 4
  238.  
  239. =item 0 or COMPRESSION_LEVEL_NONE
  240.  
  241.  
  242.  
  243. This is the same as saying
  244.  
  245.   $member->desiredCompressionMethod( COMPRESSION_STORED );
  246.  
  247. =item 1 .. 9
  248.  
  249.  
  250.  
  251. 1 gives the best speed and worst compression, and 9 gives the
  252. best compression and worst speed.
  253.  
  254. =item COMPRESSION_LEVEL_FASTEST
  255.  
  256.  
  257.  
  258. This is a synonym for level 1.
  259.  
  260. =item COMPRESSION_LEVEL_BEST_COMPRESSION
  261.  
  262.  
  263.  
  264. This is a synonym for level 9.
  265.  
  266. =item COMPRESSION_LEVEL_DEFAULT
  267.  
  268.  
  269.  
  270. This gives a good compromise between speed and compression,
  271. and is currently equivalent to 6 (this is in the zlib code).
  272. This is the level that will be used if not specified.
  273.  
  274. =back
  275.  
  276. =head1 Archive::Zip methods
  277.  
  278.  
  279. The Archive::Zip class (and its invisible subclass Archive::Zip::Archive)
  280. implement generic zip file functionality. Creating a new Archive::Zip object
  281. actually makes an Archive::Zip::Archive object, but you don't have to worry
  282. about this unless you're subclassing.
  283.  
  284. =head2 Constructor
  285.  
  286.  
  287. =over 4
  288.  
  289. =item new( [$fileName] )
  290.  
  291.  
  292.  
  293. Make a new, empty zip archive.
  294.  
  295.     my $zip = Archive::Zip->new();
  296.  
  297. If an additional argument is passed, new() will call read()
  298. to read the contents of an archive:
  299.  
  300.     my $zip = Archive::Zip->new( 'xyz.zip' );
  301.  
  302. If a filename argument is passed and the read fails for any
  303. reason, new will return undef. For this reason, it may be
  304. better to call read separately.
  305.  
  306. =back
  307.  
  308. =head2 Zip Archive Utility Methods
  309.  
  310.  
  311. These Archive::Zip methods may be called as functions or as object
  312. methods. Do not call them as class methods:
  313.  
  314.     $zip = Archive::Zip->new();
  315.     $crc = Archive::Zip::computeCRC32( 'ghijkl' );    # OK
  316.     $crc = $zip->computeCRC32( 'ghijkl' );            # also OK
  317.     $crc = Archive::Zip->computeCRC32( 'ghijkl' );    # NOT OK
  318.  
  319. =over 4
  320.  
  321. =item Archive::Zip::computeCRC32( $string [, $crc] )
  322.  
  323.  
  324.  
  325. This is a utility function that uses the Compress::Zlib CRC
  326. routine to compute a CRC-32. You can get the CRC of a string:
  327.  
  328.     $crc = Archive::Zip::computeCRC32( $string );
  329.  
  330. Or you can compute the running CRC:
  331.  
  332.     $crc = 0;
  333.     $crc = Archive::Zip::computeCRC32( 'abcdef', $crc );
  334.     $crc = Archive::Zip::computeCRC32( 'ghijkl', $crc );
  335.  
  336. =item Archive::Zip::setChunkSize( $number )
  337.  
  338.  
  339.  
  340. Report or change chunk size used for reading and writing.
  341. Currently, this defaults to 32K. This also changes the chunk
  342. size used for Compress::Zlib. You must call setChunkSize()
  343. before reading or writing. This is not exportable, so you
  344. must call it like:
  345.  
  346.     Archive::Zip::setChunkSize( 4096 );
  347.  
  348. or as a method on a zip (though this is a global setting).
  349. Returns old chunk size.
  350.  
  351. =item Archive::Zip::chunkSize()
  352.  
  353.  
  354.  
  355. Returns the current chunk size:
  356.  
  357.     my $chunkSize = Archive::Zip::chunkSize();
  358.  
  359. =item Archive::Zip::setErrorHandler( \&subroutine )
  360.  
  361.  
  362.  
  363. Change the subroutine called with error strings. This
  364. defaults to \&Carp::carp, but you may want to change it to
  365. get the error strings. This is not exportable, so you must
  366. call it like:
  367.  
  368.     Archive::Zip::setErrorHandler( \&myErrorHandler );
  369.  
  370. If no error handler is passed, resets handler to default.
  371. Returns old error handler. Note that if you call Carp::carp
  372. or a similar routine or if you're chaining to the default
  373. error handler from your error handler, you may want to
  374. increment the number of caller levels that are skipped (do
  375. not just set it to a number):
  376.  
  377.     $Carp::CarpLevel++;
  378.  
  379. =item Archive::Zip::tempName( [$tmpdir] )
  380.  
  381.  
  382.  
  383. Create a unique name for a temp file, in the given directory
  384. or in the first one of:
  385.  
  386.     /tmp
  387.     $ENV{TMPDIR}
  388.     $ENV{TEMP}
  389.     .
  390.  
  391. =item Archive::Zip::tempFile( [$tmpdir] )
  392.  
  393.  
  394.  
  395. Create a uniquely named temp file. It will be returned open
  396. for read/write. If C<$tmpdir> is given, it is used as the
  397. name of a directory to create the file in. If not given,
  398. creates the file in the first directory found in this list:
  399.  
  400.     /tmp
  401.     $ENV{TMPDIR}
  402.     $ENV{TEMP}
  403.     .
  404.  
  405. Will create C<$tmpdir> if it doesn't exist; will C<die> if it
  406. can't create the directory. Returns file handle and name:
  407.  
  408.     my ($fh, $name) = Archive::Zip::tempFile();
  409.     my ($fh, $name) = Archive::Zip::tempFile('myTempDir');
  410.     my $fh = Archive::Zip::tempFile();  # if you don't need the name
  411.  
  412. =back
  413.  
  414. =head2 Zip Archive Accessors
  415.  
  416.  
  417. =over 4
  418.  
  419. =item members()
  420.  
  421.  
  422.  
  423. Return a copy of the members array
  424.  
  425.     my @members = $zip->members();
  426.  
  427. =item numberOfMembers()
  428.  
  429.  
  430.  
  431. Return the number of members I have
  432.  
  433. =item memberNames()
  434.  
  435.  
  436.  
  437. Return a list of the (internal) file names of the zip members
  438.  
  439. =item memberNamed( $string )
  440.  
  441.  
  442.  
  443. Return ref to member whose filename equals given filename or
  444. undef. C<$string> must be in Zip (Unix) filename format.
  445.  
  446. =item membersMatching( $regex )
  447.  
  448.  
  449.  
  450. Return array of members whose filenames match given regular
  451. expression in list context. Returns number of matching
  452. members in scalar context.
  453.  
  454.     my @textFileMembers = $zip->membersMatching( '.*\.txt' );
  455.     # or
  456.     my $numberOfTextFiles = $zip->membersMatching( '.*\.txt' );
  457.  
  458. =item diskNumber()
  459.  
  460.  
  461.  
  462. Return the disk that I start on. Not used for writing zips,
  463. but might be interesting if you read a zip in. This should be
  464. 0, as Archive::Zip does not handle multi-volume archives.
  465.  
  466. =item diskNumberWithStartOfCentralDirectory()
  467.  
  468.  
  469.  
  470. Return the disk number that holds the beginning of the
  471. central directory. Not used for writing zips, but might be
  472. interesting if you read a zip in. This should be 0, as
  473. Archive::Zip does not handle multi-volume archives.
  474.  
  475. =item numberOfCentralDirectoriesOnThisDisk()
  476.  
  477.  
  478.  
  479. Return the number of CD structures in the zipfile last read in.
  480. Not used for writing zips, but might be interesting if you read a zip
  481. in.
  482.  
  483. =item numberOfCentralDirectories()
  484.  
  485.  
  486.  
  487. Return the number of CD structures in the zipfile last read in.
  488. Not used for writing zips, but might be interesting if you read a zip
  489. in.
  490.  
  491. =item centralDirectorySize()
  492.  
  493.  
  494.  
  495. Returns central directory size, as read from an external zip
  496. file. Not used for writing zips, but might be interesting if
  497. you read a zip in.
  498.  
  499. =item centralDirectoryOffsetWRTStartingDiskNumber()
  500.  
  501.  
  502.  
  503. Returns the offset into the zip file where the CD begins. Not
  504. used for writing zips, but might be interesting if you read a
  505. zip in.
  506.  
  507. =item zipfileComment( [$string] )
  508.  
  509.  
  510.  
  511. Get or set the zipfile comment. Returns the old comment.
  512.  
  513.     print $zip->zipfileComment();
  514.     $zip->zipfileComment( 'New Comment' );
  515.  
  516. =item eocdOffset()
  517.  
  518.  
  519.  
  520. Returns the (unexpected) number of bytes between where the
  521. EOCD was found and where it expected to be. This is normally
  522. 0, but would be positive if something (a virus, perhaps) had
  523. added bytes somewhere before the EOCD. Not used for writing
  524. zips, but might be interesting if you read a zip in. Here is
  525. an example of how you can diagnose this:
  526.  
  527.   my $zip = Archive::Zip->new('somefile.zip');
  528.   if ($zip->eocdOffset())
  529.   {
  530.     warn "A virus has added ", $zip->eocdOffset, " bytes of garbage\n";
  531.   }
  532.  
  533. The C<eocdOffset()> is used to adjust the starting position of member
  534. headers, if necessary.
  535.  
  536. =item fileName()
  537.  
  538.  
  539.  
  540. Returns the name of the file last read from. If nothing has
  541. been read yet, returns an empty string; if read from a file
  542. handle, returns the handle in string form.
  543.  
  544. =back
  545.  
  546. =head2 Zip Archive Member Operations
  547.  
  548.  
  549. Various operations on a zip file modify members. When a member is
  550. passed as an argument, you can either use a reference to the member
  551. itself, or the name of a member. Of course, using the name requires
  552. that names be unique within a zip (this is not enforced).
  553.  
  554. =over 4
  555.  
  556. =item removeMember( $memberOrName )
  557.  
  558.  
  559.  
  560. Remove and return the given member, or match its name and
  561. remove it. Returns undef if member or name doesn't exist in this
  562. Zip. No-op if member does not belong to this zip.
  563.  
  564. =item replaceMember( $memberOrName, $newMember )
  565.  
  566.  
  567.  
  568. Remove and return the given member, or match its name and
  569. remove it. Replace with new member. Returns undef if member or
  570. name doesn't exist in this Zip, or if C<$newMember> is undefined.
  571.  
  572.  
  573. It is an (undiagnosed) error to provide a C<$newMember> that is a
  574. member of the zip being modified.
  575.  
  576.     my $member1 = $zip->removeMember( 'xyz' );
  577.     my $member2 = $zip->replaceMember( 'abc', $member1 );
  578.     # now, $member2 (named 'abc') is not in $zip,
  579.     # and $member1 (named 'xyz') is, having taken $member2's place.
  580.  
  581. =item extractMember( $memberOrName [, $extractedName ] )
  582.  
  583.  
  584.  
  585. Extract the given member, or match its name and extract it.
  586. Returns undef if member doesn't exist in this Zip. If
  587. optional second arg is given, use it as the name of the
  588. extracted member. Otherwise, the internal filename of the
  589. member is used as the name of the extracted file or
  590. directory.
  591. If you pass C<$extractedName>, it should be in the local file
  592. system's format.
  593. All necessary directories will be created. Returns C<AZ_OK>
  594. on success.
  595.  
  596. =item extractMemberWithoutPaths( $memberOrName [, $extractedName ] )
  597.  
  598.  
  599.  
  600. Extract the given member, or match its name and extract it.
  601. Does not use path information (extracts into the current
  602. directory). Returns undef if member doesn't exist in this
  603. Zip.
  604. If optional second arg is given, use it as the name of the
  605. extracted member (its paths will be deleted too). Otherwise,
  606. the internal filename of the member (minus paths) is used as
  607. the name of the extracted file or directory. Returns C<AZ_OK>
  608. on success.
  609.  
  610. =item addMember( $member )
  611.  
  612.  
  613.  
  614. Append a member (possibly from another zip file) to the zip
  615. file. Returns the new member. Generally, you will use
  616. addFile(), addDirectory(), addFileOrDirectory(), addString(),
  617. or read() to add members.
  618.  
  619.     # Move member named 'abc' to end of zip:
  620.     my $member = $zip->removeMember( 'abc' );
  621.     $zip->addMember( $member );
  622.  
  623. =item updateMember( $memberOrName, $fileName )
  624.  
  625.  
  626.  
  627. Update a single member from the file or directory named C<$fileName>.
  628. Returns the (possibly added or updated) member, if any; C<undef> on
  629. errors.
  630. The comparison is based on C<lastModTime()> and (in the case of a
  631. non-directory) the size of the file.
  632.  
  633. =item addFile( $fileName [, $newName ] )
  634.  
  635.  
  636.  
  637. Append a member whose data comes from an external file,
  638. returning the member or undef. The member will have its file
  639. name set to the name of the external file, and its
  640. desiredCompressionMethod set to COMPRESSION_DEFLATED. The
  641. file attributes and last modification time will be set from
  642. the file.
  643. If the name given does not represent a readable plain file or
  644. symbolic link, undef will be returned. C<$fileName> must be
  645. in the format required for the local file system.
  646. The optional C<$newName> argument sets the internal file name
  647. to something different than the given $fileName. C<$newName>,
  648. if given, must be in Zip name format (i.e. Unix).
  649. The text mode bit will be set if the contents appears to be
  650. text (as returned by the C<-T> perl operator).
  651.  
  652.  
  653. I<NOTE> that you shouldn't (generally) use absolute path names
  654. in zip member names, as this will cause problems with some zip
  655. tools as well as introduce a security hole and make the zip
  656. harder to use.
  657.  
  658. =item addDirectory( $directoryName [, $fileName ] )
  659.  
  660.  
  661.  
  662. Append a member created from the given directory name. The
  663. directory name does not have to name an existing directory.
  664. If the named directory exists, the file modification time and
  665. permissions are set from the existing directory, otherwise
  666. they are set to now and permissive default permissions.
  667. C<$directoryName> must be in local file system format.
  668. The optional second argument sets the name of the archive
  669. member (which defaults to C<$directoryName>). If given, it
  670. must be in Zip (Unix) format.
  671. Returns the new member.
  672.  
  673. =item addFileOrDirectory( $name [, $newName ] )
  674.  
  675.  
  676.  
  677. Append a member from the file or directory named $name. If
  678. $newName is given, use it for the name of the new member.
  679. Will add or remove trailing slashes from $newName as needed.
  680. C<$name> must be in local file system format.
  681. The optional second argument sets the name of the archive
  682. member (which defaults to C<$name>). If given, it must be in
  683. Zip (Unix) format.
  684.  
  685. =item addString( $stringOrStringRef, $name )
  686.  
  687.  
  688.  
  689. Append a member created from the given string or string
  690. reference. The name is given by the second argument.
  691. Returns the new member. The last modification time will be
  692. set to now, and the file attributes will be set to permissive
  693. defaults.
  694.  
  695.     my $member = $zip->addString( 'This is a test', 'test.txt' );
  696.  
  697. =item contents( $memberOrMemberName [, $newContents ] )
  698.  
  699.  
  700.  
  701. Returns the uncompressed data for a particular member, or
  702. undef.
  703.  
  704.     print "xyz.txt contains " . $zip->contents( 'xyz.txt' );
  705.  
  706. Also can change the contents of a member:
  707.  
  708.     $zip->contents( 'xyz.txt', 'This is the new contents' );
  709.  
  710. =back
  711.  
  712. =head2 Zip Archive I/O operations
  713.  
  714.  
  715. A Zip archive can be written to a file or file handle, or read from
  716. one.
  717.  
  718. =over 4
  719.  
  720. =item writeToFileNamed( $fileName )
  721.  
  722.  
  723.  
  724. Write a zip archive to named file. Returns C<AZ_OK> on
  725. success.
  726.  
  727.     my $status = $zip->writeToFileNamed( 'xx.zip' );
  728.     die "error somewhere" if $status != AZ_OK;
  729.  
  730. Note that if you use the same name as an existing zip file
  731. that you read in, you will clobber ZipFileMembers. So
  732. instead, write to a different file name, then delete the
  733. original.
  734. If you use the C<overwrite()> or C<overwriteAs()> methods, you can
  735. re-write the original zip in this way.
  736. C<$fileName> should be a valid file name on your system.
  737.  
  738. =item writeToFileHandle( $fileHandle [, $seekable] )
  739.  
  740.  
  741.  
  742. Write a zip archive to a file handle. Return AZ_OK on
  743. success. The optional second arg tells whether or not to try
  744. to seek backwards to re-write headers. If not provided, it is
  745. set if the Perl C<-f> test returns true. This could fail on
  746. some operating systems, though.
  747.  
  748.     my $fh = IO::File->new( 'someFile.zip', 'w' );
  749.     if ( $zip->writeToFileHandle( $fh ) != AZ_OK)
  750.         {
  751.             # error handling
  752.         }
  753.  
  754. If you pass a file handle that is not seekable (like if
  755. you're writing to a pipe or a socket), pass a false second
  756. argument:
  757.  
  758.     my $fh = IO::File->new( '| cat > somefile.zip', 'w' );
  759.     $zip->writeToFileHandle( $fh, 0 );   # fh is not seekable
  760.  
  761. If this method fails during the write of a member, that
  762. member and all following it will return false from
  763. C<wasWritten()>. See writeCentralDirectory() for a way to
  764. deal with this.
  765. If you want, you can write data to the file handle before
  766. passing it to writeToFileHandle(); this could be used (for
  767. instance) for making self-extracting archives. However, this
  768. only works reliably when writing to a real file (as opposed
  769. to STDOUT or some other possible non-file).
  770. See examples/selfex.pl for how to write a self-extracting
  771. archive.
  772.  
  773. =item writeCentralDirectory( $fileHandle [, $offset ] )
  774.  
  775.  
  776.  
  777. Writes the central directory structure to the given file
  778. handle. Returns AZ_OK on success. If given an $offset, will
  779. seek to that point before writing. This can be used for
  780. recovery in cases where writeToFileHandle or writeToFileNamed
  781. returns an IO error because of running out of space on the
  782. destination file. You can truncate the zip by seeking
  783. backwards and then writing the directory:
  784.  
  785.     my $fh = IO::File->new( 'someFile.zip', 'w' );
  786.         my $retval = $zip->writeToFileHandle( $fh );
  787.     if ( $retval == AZ_IO_ERROR )
  788.         {
  789.             my @unwritten = grep { not $_->wasWritten() } $zip->members();
  790.             if (@unwritten)
  791.             {
  792.                 $zip->removeMember( $member ) foreach my $member ( @unwritten );
  793.                 $zip->writeCentralDirectory( $fh,
  794.                     $unwritten[0]->writeLocalHeaderRelativeOffset());
  795.             }
  796.         }
  797.  
  798. =item overwriteAs( $newName )
  799.  
  800.  
  801.  
  802. Write the zip to the specified file, as safely as possible.
  803. This is done by first writing to a temp file, then renaming
  804. the original if it exists, then renaming the temp file, then
  805. deleting the renamed original if it exists. Returns AZ_OK if
  806. successful.
  807.  
  808. =item overwrite()
  809.  
  810.  
  811.  
  812. Write back to the original zip file. See overwriteAs() above.
  813. If the zip was not ever read from a file, this generates an
  814. error.
  815.  
  816. =item read( $fileName )
  817.  
  818.  
  819.  
  820. Read zipfile headers from a zip file, appending new members.
  821. Returns C<AZ_OK> or error code.
  822.  
  823.     my $zipFile = Archive::Zip->new();
  824.     my $status = $zipFile->read( '/some/FileName.zip' );
  825.  
  826. =item readFromFileHandle( $fileHandle, $filename )
  827.  
  828.  
  829.  
  830. Read zipfile headers from an already-opened file handle,
  831. appending new members. Does not close the file handle.
  832. Returns C<AZ_OK> or error code. Note that this requires a
  833. seekable file handle; reading from a stream is not yet
  834. supported.
  835.  
  836.     my $fh = IO::File->new( '/some/FileName.zip', 'r' );
  837.     my $zip1 = Archive::Zip->new();
  838.     my $status = $zip1->readFromFileHandle( $fh );
  839.     my $zip2 = Archive::Zip->new();
  840.     $status = $zip2->readFromFileHandle( $fh );
  841.  
  842. =back
  843.  
  844. =head2 Zip Archive Tree operations
  845.  
  846.  
  847. These used to be in Archive::Zip::Tree but got moved into
  848. Archive::Zip. They enable operation on an entire tree of members or
  849. files.
  850. A usage example:
  851.  
  852.   use Archive::Zip;
  853.   my $zip = Archive::Zip->new();
  854.   # add all readable files and directories below . as xyz/*
  855.   $zip->addTree( '.', 'xyz' );    
  856.   # add all readable plain files below /abc as def/*
  857.   $zip->addTree( '/abc', 'def', sub { -f && -r } );    
  858.   # add all .c files below /tmp as stuff/*
  859.   $zip->addTreeMatching( '/tmp', 'stuff', '\.c$' );
  860.   # add all .o files below /tmp as stuff/* if they aren't writable
  861.   $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { ! -w } );
  862.   # add all .so files below /tmp that are smaller than 200 bytes as stuff/*
  863.   $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { -s < 200 } );
  864.   # and write them into a file
  865.   $zip->writeToFileNamed('xxx.zip');
  866.   # now extract the same files into /tmpx
  867.   $zip->extractTree( 'stuff', '/tmpx' );
  868.  
  869. =over 4
  870.  
  871. =item $zip->addTree( $root, $dest [,$pred] ) -- Add tree of files to a zip
  872.  
  873.  
  874.  
  875. C<$root> is the root of the tree of files and directories to be
  876. added. It is a valid directory name on your system. C<$dest> is
  877. the name for the root in the zip file (undef or blank means
  878. to use relative pathnames). It is a valid ZIP directory name
  879. (that is, it uses forward slashes (/) for separating
  880. directory components). C<$pred> is an optional subroutine
  881. reference to select files: it is passed the name of the
  882. prospective file or directory using C<$_>, and if it returns
  883. true, the file or directory will be included. The default is
  884. to add all readable files and directories. For instance,
  885. using
  886.  
  887.   my $pred = sub { /\.txt/ };
  888.   $zip->addTree( '.', '', $pred );
  889.  
  890. will add all the .txt files in and below the current
  891. directory, using relative names, and making the names
  892. identical in the zipfile:
  893.  
  894.   original name           zip member name
  895.   ./xyz                   xyz
  896.   ./a/                    a/
  897.   ./a/b                   a/b
  898.  
  899. To translate absolute to relative pathnames, just pass them
  900. in: $zip->addTree( '/c/d', 'a' );
  901.  
  902.   original name           zip member name
  903.   /c/d/xyz                a/xyz
  904.   /c/d/a/                 a/a/
  905.   /c/d/a/b                a/a/b
  906.  
  907. Returns AZ_OK on success. Note that this will not follow
  908. symbolic links to directories. Note also that this does not
  909. check for the validity of filenames.
  910.  
  911.  
  912. Note that you generally I<don't> want to make zip archive member names
  913. absolute.
  914.  
  915. =item $zip->addTreeMatching( $root, $dest, $pattern [,$pred] )
  916.  
  917.  
  918.  
  919. $root is the root of the tree of files and directories to be
  920. added $dest is the name for the root in the zip file (undef
  921. means to use relative pathnames) $pattern is a (non-anchored)
  922. regular expression for filenames to match $pred is an
  923. optional subroutine reference to select files: it is passed
  924. the name of the prospective file or directory in C<$_>, and
  925. if it returns true, the file or directory will be included.
  926. The default is to add all readable files and directories. To
  927. add all files in and below the current dirctory whose names
  928. end in C<.pl>, and make them extract into a subdirectory
  929. named C<xyz>, do this:
  930.  
  931.   $zip->addTreeMatching( '.', 'xyz', '\.pl$' )
  932.  
  933. To add all I<writable> files in and below the dirctory named
  934. C</abc> whose names end in C<.pl>, and make them extract into
  935. a subdirectory named C<xyz>, do this:
  936.  
  937.   $zip->addTreeMatching( '/abc', 'xyz', '\.pl$', sub { -w } )
  938.  
  939. Returns AZ_OK on success. Note that this will not follow
  940. symbolic links to directories.
  941.  
  942. =item $zip->updateTree( $root, [ $dest, [ $pred [, $mirror]]] );
  943.  
  944.  
  945.  
  946. Update a zip file from a directory tree.
  947.  
  948. C<updateTree()> takes the same arguments as C<addTree()>, but first
  949. checks to see whether the file or directory already exists in the zip
  950. file, and whether it has been changed.
  951.  
  952. If the fourth argument C<$mirror> is true, then delete all my members
  953. if corresponding files weren't found.
  954.  
  955.  
  956. Returns an error code or AZ_OK of all is well.
  957.  
  958. =item $zip->extractTree()
  959.  
  960.  
  961.  
  962. =item $zip->extractTree( $root )
  963.  
  964.  
  965.  
  966. =item $zip->extractTree( $root, $dest )
  967.  
  968.  
  969.  
  970. =item $zip->extractTree( $root, $dest, $volume )
  971.  
  972.  
  973.  
  974. If you don't give any arguments at all, will extract all the
  975. files in the zip with their original names.
  976.  
  977.  
  978. If you supply one argument for C<$root>, C<extractTree> will extract
  979. all the members whose names start with C<$root> into the current
  980. directory, stripping off C<$root> first.
  981. C<$root> is in Zip (Unix) format.
  982. For instance,
  983.  
  984.   $zip->extractTree( 'a' );
  985.  
  986. when applied to a zip containing the files:
  987. a/x a/b/c ax/d/e d/e will extract:
  988.  
  989.  
  990. a/x as ./x
  991.  
  992.  
  993. a/b/c as ./b/c
  994.  
  995.  
  996. If you give two arguments, C<extractTree> extracts all the members
  997. whose names start with C<$root>. It will translate C<$root> into
  998. C<$dest> to construct the destination file name.
  999. C<$root> and C<$dest> are in Zip (Unix) format.
  1000. For instance,
  1001.  
  1002.    $zip->extractTree( 'a', 'd/e' );
  1003.  
  1004. when applied to a zip containing the files:
  1005. a/x a/b/c ax/d/e d/e will extract:
  1006.  
  1007.  
  1008. a/x to d/e/x
  1009.  
  1010.  
  1011. a/b/c to d/e/b/c and ignore ax/d/e and d/e
  1012.  
  1013.  
  1014. If you give three arguments, C<extractTree> extracts all the members
  1015. whose names start with C<$root>. It will translate C<$root> into
  1016. C<$dest> to construct the destination file name, and then it will
  1017. convert to local file system format, using C<$volume> as the name of
  1018. the destination volume.
  1019.  
  1020.  
  1021. C<$root> and C<$dest> are in Zip (Unix) format.
  1022.  
  1023.  
  1024. C<$volume> is in local file system format.
  1025.  
  1026.  
  1027. For instance, under Windows,
  1028.  
  1029.    $zip->extractTree( 'a', 'd/e', 'f:' );
  1030.  
  1031. when applied to a zip containing the files:
  1032. a/x a/b/c ax/d/e d/e will extract:
  1033.  
  1034.  
  1035. a/x to f:d/e/x
  1036.  
  1037.  
  1038. a/b/c to f:d/e/b/c and ignore ax/d/e and d/e
  1039.  
  1040.  
  1041. If you want absolute paths (the prior example used paths relative to
  1042. the current directory on the destination volume, you can specify these
  1043. in C<$dest>:
  1044.  
  1045.    $zip->extractTree( 'a', '/d/e', 'f:' );
  1046.  
  1047. when applied to a zip containing the files:
  1048. a/x a/b/c ax/d/e d/e will extract:
  1049.  
  1050.  
  1051. a/x to f:\d\e\x
  1052.  
  1053.  
  1054. a/b/c to f:\d\e\b\c and ignore ax/d/e and d/e
  1055.  
  1056.  
  1057. =back
  1058.  
  1059. =head1 MEMBER OPERATIONS
  1060.  
  1061.  
  1062. =head2 Member Class Methods
  1063.  
  1064.  
  1065. Several constructors allow you to construct members without adding
  1066. them to a zip archive. These work the same as the addFile(),
  1067. addDirectory(), and addString() zip instance methods described above,
  1068. but they don't add the new members to a zip.
  1069.  
  1070. =over 4
  1071.  
  1072. =item Archive::Zip::Member->newFromString( $stringOrStringRef [, $fileName] )
  1073.  
  1074.  
  1075.  
  1076. Construct a new member from the given string. Returns undef
  1077. on error.
  1078.  
  1079.     my $member = Archive::Zip::Member->newFromString( 'This is a test',
  1080.                                                  'xyz.txt' );
  1081.  
  1082. =item newFromFile( $fileName )
  1083.  
  1084.  
  1085.  
  1086. Construct a new member from the given file. Returns undef on
  1087. error.
  1088.  
  1089.     my $member = Archive::Zip::Member->newFromFile( 'xyz.txt' );
  1090.  
  1091. =item newDirectoryNamed( $directoryName [, $zipname ] )
  1092.  
  1093.  
  1094.  
  1095. Construct a new member from the given directory.
  1096. C<$directoryName> must be a valid name on your file system; it doesn't
  1097. have to exist.
  1098.  
  1099.  
  1100. If given, C<$zipname> will be the name of the zip member; it must be a
  1101. valid Zip (Unix) name. If not given, it will be converted from
  1102. C<$directoryName>.
  1103.  
  1104.  
  1105. Returns undef on error.
  1106.  
  1107.     my $member = Archive::Zip::Member->newDirectoryNamed( 'CVS/' );
  1108.  
  1109. =back
  1110.  
  1111. =head2 Member Simple accessors
  1112.  
  1113.  
  1114. These methods get (and/or set) member attribute values.
  1115.  
  1116. =over 4
  1117.  
  1118. =item versionMadeBy()
  1119.  
  1120.  
  1121.  
  1122. Gets the field from the member header.
  1123.  
  1124. =item fileAttributeFormat( [$format] )
  1125.  
  1126.  
  1127.  
  1128. Gets or sets the field from the member header. These are
  1129. C<FA_*> values.
  1130.  
  1131. =item versionNeededToExtract()
  1132.  
  1133.  
  1134.  
  1135. Gets the field from the member header.
  1136.  
  1137. =item bitFlag()
  1138.  
  1139.  
  1140.  
  1141. Gets the general purpose bit field from the member header.
  1142. This is where the C<GPBF_*> bits live.
  1143.  
  1144. =item compressionMethod()
  1145.  
  1146.  
  1147.  
  1148. Returns the member compression method. This is the method
  1149. that is currently being used to compress the member data.
  1150. This will be COMPRESSION_STORED for added string or file
  1151. members, or any of the C<COMPRESSION_*> values for members
  1152. from a zip file. However, this module can only handle members
  1153. whose data is in COMPRESSION_STORED or COMPRESSION_DEFLATED
  1154. format.
  1155.  
  1156. =item desiredCompressionMethod( [$method] )
  1157.  
  1158.  
  1159.  
  1160. Get or set the member's C<desiredCompressionMethod>. This is
  1161. the compression method that will be used when the member is
  1162. written. Returns prior desiredCompressionMethod. Only
  1163. COMPRESSION_DEFLATED or COMPRESSION_STORED are valid
  1164. arguments. Changing to COMPRESSION_STORED will change the
  1165. member desiredCompressionLevel to 0; changing to
  1166. COMPRESSION_DEFLATED will change the member
  1167. desiredCompressionLevel to COMPRESSION_LEVEL_DEFAULT.
  1168.  
  1169. =item desiredCompressionLevel( [$method] )
  1170.  
  1171.  
  1172.  
  1173. Get or set the member's desiredCompressionLevel This is the
  1174. method that will be used to write. Returns prior
  1175. desiredCompressionLevel. Valid arguments are 0 through 9,
  1176. COMPRESSION_LEVEL_NONE, COMPRESSION_LEVEL_DEFAULT,
  1177. COMPRESSION_LEVEL_BEST_COMPRESSION, and
  1178. COMPRESSION_LEVEL_FASTEST. 0 or COMPRESSION_LEVEL_NONE will
  1179. change the desiredCompressionMethod to COMPRESSION_STORED.
  1180. All other arguments will change the desiredCompressionMethod
  1181. to COMPRESSION_DEFLATED.
  1182.  
  1183. =item externalFileName()
  1184.  
  1185.  
  1186.  
  1187. Return the member's external file name, if any, or undef.
  1188.  
  1189. =item fileName()
  1190.  
  1191.  
  1192.  
  1193. Get or set the member's internal filename. Returns the
  1194. (possibly new) filename. Names will have backslashes
  1195. converted to forward slashes, and will have multiple
  1196. consecutive slashes converted to single ones.
  1197.  
  1198. =item lastModFileDateTime()
  1199.  
  1200.  
  1201.  
  1202. Return the member's last modification date/time stamp in
  1203. MS-DOS format.
  1204.  
  1205. =item lastModTime()
  1206.  
  1207.  
  1208.  
  1209. Return the member's last modification date/time stamp,
  1210. converted to unix localtime format.
  1211.  
  1212.     print "Mod Time: " . scalar( localtime( $member->lastModTime() ) );
  1213.  
  1214. =item setLastModFileDateTimeFromUnix()
  1215.  
  1216.  
  1217.  
  1218. Set the member's lastModFileDateTime from the given unix
  1219. time.
  1220.  
  1221.     $member->setLastModFileDateTimeFromUnix( time() );
  1222.  
  1223. =item internalFileAttributes()
  1224.  
  1225.  
  1226.  
  1227. Return the internal file attributes field from the zip
  1228. header. This is only set for members read from a zip file.
  1229.  
  1230. =item externalFileAttributes()
  1231.  
  1232.  
  1233.  
  1234. Return member attributes as read from the ZIP file. Note that
  1235. these are NOT UNIX!
  1236.  
  1237. =item unixFileAttributes( [$newAttributes] )
  1238.  
  1239.  
  1240.  
  1241. Get or set the member's file attributes using UNIX file
  1242. attributes. Returns old attributes.
  1243.  
  1244.     my $oldAttribs = $member->unixFileAttributes( 0666 );
  1245.  
  1246. Note that the return value has more than just the file
  1247. permissions, so you will have to mask off the lowest bits for
  1248. comparisions.
  1249.  
  1250. =item localExtraField( [$newField] )
  1251.  
  1252.  
  1253.  
  1254. Gets or sets the extra field that was read from the local
  1255. header. This is not set for a member from a zip file until
  1256. after the member has been written out. The extra field must
  1257. be in the proper format.
  1258.  
  1259. =item cdExtraField( [$newField] )
  1260.  
  1261.  
  1262.  
  1263. Gets or sets the extra field that was read from the central
  1264. directory header. The extra field must be in the proper
  1265. format.
  1266.  
  1267. =item extraFields()
  1268.  
  1269.  
  1270.  
  1271. Return both local and CD extra fields, concatenated.
  1272.  
  1273. =item fileComment( [$newComment] )
  1274.  
  1275.  
  1276.  
  1277. Get or set the member's file comment.
  1278.  
  1279. =item hasDataDescriptor()
  1280.  
  1281.  
  1282.  
  1283. Get or set the data descriptor flag. If this is set, the
  1284. local header will not necessarily have the correct data
  1285. sizes. Instead, a small structure will be stored at the end
  1286. of the member data with these values. This should be
  1287. transparent in normal operation.
  1288.  
  1289. =item crc32()
  1290.  
  1291.  
  1292.  
  1293. Return the CRC-32 value for this member. This will not be set
  1294. for members that were constructed from strings or external
  1295. files until after the member has been written.
  1296.  
  1297. =item crc32String()
  1298.  
  1299.  
  1300.  
  1301. Return the CRC-32 value for this member as an 8 character
  1302. printable hex string. This will not be set for members that
  1303. were constructed from strings or external files until after
  1304. the member has been written.
  1305.  
  1306. =item compressedSize()
  1307.  
  1308.  
  1309.  
  1310. Return the compressed size for this member. This will not be
  1311. set for members that were constructed from strings or
  1312. external files until after the member has been written.
  1313.  
  1314. =item uncompressedSize()
  1315.  
  1316.  
  1317.  
  1318. Return the uncompressed size for this member.
  1319.  
  1320. =item isEncrypted()
  1321.  
  1322.  
  1323.  
  1324. Return true if this member is encrypted. The Archive::Zip
  1325. module does not currently create or extract encrypted
  1326. members.
  1327.  
  1328. =item isTextFile( [$flag] )
  1329.  
  1330.  
  1331.  
  1332. Returns true if I am a text file. Also can set the status if
  1333. given an argument (then returns old state). Note that this
  1334. module does not currently do anything with this flag upon
  1335. extraction or storage. That is, bytes are stored in native
  1336. format whether or not they came from a text file.
  1337.  
  1338. =item isBinaryFile()
  1339.  
  1340.  
  1341.  
  1342. Returns true if I am a binary file. Also can set the status
  1343. if given an argument (then returns old state). Note that this
  1344. module does not currently do anything with this flag upon
  1345. extraction or storage. That is, bytes are stored in native
  1346. format whether or not they came from a text file.
  1347.  
  1348. =item extractToFileNamed( $fileName )
  1349.  
  1350.  
  1351.  
  1352. Extract me to a file with the given name. The file will be
  1353. created with default modes. Directories will be created as
  1354. needed.
  1355. The C<$fileName> argument should be a valid file name on your
  1356. file system.
  1357. Returns AZ_OK on success.
  1358.  
  1359. =item isDirectory()
  1360.  
  1361.  
  1362.  
  1363. Returns true if I am a directory.
  1364.  
  1365. =item writeLocalHeaderRelativeOffset()
  1366.  
  1367.  
  1368.  
  1369. Returns the file offset in bytes the last time I was written.
  1370.  
  1371. =item wasWritten()
  1372.  
  1373.  
  1374.  
  1375. Returns true if I was successfully written. Reset at the
  1376. beginning of a write attempt.
  1377.  
  1378. =back
  1379.  
  1380. =head2 Low-level member data reading
  1381.  
  1382.  
  1383. It is possible to use lower-level routines to access member data
  1384. streams, rather than the extract* methods and contents(). For
  1385. instance, here is how to print the uncompressed contents of a member
  1386. in chunks using these methods:
  1387.  
  1388.     my ( $member, $status, $bufferRef );
  1389.     $member = $zip->memberNamed( 'xyz.txt' );
  1390.     $member->desiredCompressionMethod( COMPRESSION_STORED );
  1391.     $status = $member->rewindData();
  1392.     die "error $status" unless $status == AZ_OK;
  1393.     while ( ! $member->readIsDone() )
  1394.     {
  1395.     ( $bufferRef, $status ) = $member->readChunk();
  1396.     die "error $status"
  1397.                 if $status != AZ_OK && $status != AZ_STREAM_END;
  1398.     # do something with $bufferRef:
  1399.     print $$bufferRef;
  1400.     }
  1401.     $member->endRead();
  1402.  
  1403. =over 4
  1404.  
  1405. =item readChunk( [$chunkSize] )
  1406.  
  1407.  
  1408.  
  1409. This reads the next chunk of given size from the member's
  1410. data stream and compresses or uncompresses it as necessary,
  1411. returning a reference to the bytes read and a status. If size
  1412. argument is not given, defaults to global set by
  1413. Archive::Zip::setChunkSize. Status is AZ_OK on success until
  1414. the last chunk, where it returns AZ_STREAM_END. Returns C<(
  1415. \$bytes, $status)>.
  1416.  
  1417.     my ( $outRef, $status ) = $self->readChunk();
  1418.     print $$outRef if $status != AZ_OK && $status != AZ_STREAM_END;
  1419.  
  1420. =item rewindData()
  1421.  
  1422.  
  1423.  
  1424. Rewind data and set up for reading data streams or writing
  1425. zip files. Can take options for C<inflateInit()> or
  1426. C<deflateInit()>, but this isn't likely to be necessary.
  1427. Subclass overrides should call this method. Returns C<AZ_OK>
  1428. on success.
  1429.  
  1430. =item endRead()
  1431.  
  1432.  
  1433.  
  1434. Reset the read variables and free the inflater or deflater.
  1435. Must be called to close files, etc. Returns AZ_OK on success.
  1436.  
  1437. =item readIsDone()
  1438.  
  1439.  
  1440.  
  1441. Return true if the read has run out of data or errored out.
  1442.  
  1443. =item contents()
  1444.  
  1445.  
  1446.  
  1447. Return the entire uncompressed member data or undef in scalar
  1448. context. When called in array context, returns C<( $string,
  1449. $status )>; status will be AZ_OK on success:
  1450.  
  1451.     my $string = $member->contents();
  1452.     # or
  1453.     my ( $string, $status ) = $member->contents();
  1454.     die "error $status" unless $status == AZ_OK;
  1455.  
  1456. Can also be used to set the contents of a member (this may
  1457. change the class of the member):
  1458.  
  1459.     $member->contents( "this is my new contents" );
  1460.  
  1461. =item extractToFileHandle( $fh )
  1462.  
  1463.  
  1464.  
  1465. Extract (and uncompress, if necessary) the member's contents
  1466. to the given file handle. Return AZ_OK on success.
  1467.  
  1468. =back
  1469.  
  1470. =head1 Archive::Zip::FileMember methods
  1471.  
  1472.  
  1473. The Archive::Zip::FileMember class extends Archive::Zip::Member. It is the
  1474. base class for both ZipFileMember and NewFileMember classes. This class adds
  1475. an C<externalFileName> and an C<fh> member to keep track of the external
  1476. file.
  1477.  
  1478. =over 4
  1479.  
  1480. =item externalFileName()
  1481.  
  1482.  
  1483.  
  1484. Return the member's external filename.
  1485.  
  1486. =item fh()
  1487.  
  1488.  
  1489.  
  1490. Return the member's read file handle. Automatically opens file if
  1491. necessary.
  1492.  
  1493. =back
  1494.  
  1495. =head1 Archive::Zip::ZipFileMember methods
  1496.  
  1497.  
  1498. The Archive::Zip::ZipFileMember class represents members that have been read
  1499. from external zip files.
  1500.  
  1501. =over 4
  1502.  
  1503. =item diskNumberStart()
  1504.  
  1505.  
  1506.  
  1507. Returns the disk number that the member's local header resides in.
  1508. Should be 0.
  1509.  
  1510. =item localHeaderRelativeOffset()
  1511.  
  1512.  
  1513.  
  1514. Returns the offset into the zip file where the member's local header
  1515. is.
  1516.  
  1517. =item dataOffset()
  1518.  
  1519.  
  1520.  
  1521. Returns the offset from the beginning of the zip file to the member's
  1522. data.
  1523.  
  1524. =back
  1525.  
  1526. =head1 REQUIRED MODULES
  1527.  
  1528.  
  1529. L<Archive::Zip|Archive::Zip> requires several other modules:
  1530.  
  1531.  
  1532. L<Carp|Carp>
  1533.  
  1534.  
  1535. L<Compress::Zlib|Compress::Zlib>
  1536.  
  1537.  
  1538. L<Cwd|Cwd>
  1539.  
  1540.  
  1541. L<File::Basename|File::Basename>
  1542.  
  1543.  
  1544. L<File::Copy|File::Copy>
  1545.  
  1546.  
  1547. L<File::Find|File::Find>
  1548.  
  1549.  
  1550. L<File::Path|File::Path>
  1551.  
  1552.  
  1553. L<File::Spec|File::Spec>
  1554.  
  1555.  
  1556. L<File::Spec|File::Spec>
  1557.  
  1558.  
  1559. L<IO::File|IO::File>
  1560.  
  1561.  
  1562. L<IO::Seekable|IO::Seekable>
  1563.  
  1564.  
  1565. L<Time::Local|Time::Local>
  1566.  
  1567.  
  1568. =head1 AUTHOR
  1569.  
  1570.  
  1571. Ned Konz, <nedkonz@cpan.org>
  1572.  
  1573.  
  1574. File attributes code by Maurice Aubrey <maurice@lovelyfilth.com>
  1575.  
  1576. =head1 COPYRIGHT
  1577.  
  1578.  
  1579. Copyright (c) 2000-2003 Ned Konz. All rights reserved. This program is free
  1580. software; you can redistribute it and/or modify it under the same terms as
  1581. Perl itself.
  1582.  
  1583. =head1 SEE ALSO
  1584.  
  1585.  
  1586. L<Compress::Zlib>
  1587.  
  1588.  
  1589. L<Archive::Tar>
  1590.  
  1591.  
  1592. There is a Japanese translation of this
  1593. document at L<http://www.necoware.com/~deq/perl/doc-ja/Archive-Zip.html> that
  1594. was done by DEQ <deq@oct.zaq.ne.jp> . Thanks! 
  1595.  
  1596.