Samson Monaco Tutankhamen > Archive-TarGzip > Archive::TarGzip

Download:
Archive-TarGzip-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Archive::TarGzip - save and restore files to and from compressed tape archives (tar)

SYNOPSIS ^

 ######
 # Subroutine Interface
 #  
 use Archive::TarGzip qw(parse_header tar untar);

 $tar_file = tar(@file, \@options);
 $tar_file = tar(@file);

 $success = untar(@file);
 $success = untar(@file, \@options);

 \%tar_header = parse_header($buffer);

 ######
 # File subroutines
 # 
 use Archive::TarGzip;

 tie *TAR_FILEHANDLE, 'Tie::Layers'
 tie *TAR_FILEHANDLE, 'Tie::Layers', @options

 $success = open(TAR_FILEHANDLE, $tar_file);
 $success = open(TAR_FILEHANDLE, $mode, $tar_file);

 $success = print TAR_FILEHANDLE $file_name; 
 $success = print TAR_FILEHANDLE $file_name, $file_contents;

 \%tar_header = <TAR_FILEHANDLE>;

 $success = close(TAR_FILEHANDLE);

 ######
 # Object 
 # 
 tie *TAR_FILEHANDLE, 'Tie::Layers';
 tie *TAR_FILEHANDLE, 'Tie::Layers', @options;

 $tar = tied \*TAR_FILEHANDLE; 
 $tar = new Archive::TarGzip( ); 
 $tar = new Archive::TarGzip(@options); 

 $success = $tar->OPEN( $tar_file, \@options);
 $success = $tar->OPEN( $mode, $tar_file, \@options);

 $success = $tar->PRINT($file_name);
 $success = $tar->PRINT($file_name, $file_contents);

 \%tar_header = $tar->READLINE(\@options);
 \%tar_header = $tar->READLINE(@file, \@options);

 $status = $tar->target( \$buffer, $size);
 $success = $tar->CLOSE();

DESCRIPTION ^

The Archive::TarGzip module provides tar subroutine to archive a list of files in an archive file in the tar format. The archive file may be optionally compressed using the gzip compression routines. The Archive::TarGzip module also provides a untar subroutine that can extract the files from the tar or tar/gzip archive files. The tar and untar top level subroutines use methods from the Archive::TarGzip class.

The Archive::TarGzip class has many similarities to the very mature Archive::Tar class being at least three years older. The newer Archive::TarGzip relied very heavy on the work of the author of the Archive::Tar and in many instance the Archive::Tar is a better solution.

Altough the underlying tar file format is the same and similar code is used to access the data in the underlying tar files, the interace bewteen the two are completely different. The Archive::TarGzip is built on a Tie File Handle type interface. The nthe Archive::TarGzip provide means to access individual files within the archive file without bringing the entire archive file into memory. When the gzip compression option is active, the compression is performed on the fly without creating an intermediate uncompressed tar file.

METHODS ^

tar

 $tar_file = Archive::TarGzip->tar(@file, [\%options or\@options]);
 $tar_file = tar(@file, [\%options or\@options]); # only if imported

The tar subroutine creates a tar archive file containing the files in the @file list. The name of the file is $option{tar_file}. The tar subroutine will enforce that the $option{tar_file} has the .tar or .tar.gz extensions (uses the $option{compress} to determine which one).

The tar subroutine will add directories to the @file list in the correct order needed to create the directories so that they will be available to extract the @files files from the tar archive file.

If the $option{src_dir} is present, the tar subroutine will change to the $option{src_dir} before reading the @file list. The subroutine will restore the original directory after processing.

If the $option{dest_dir} is present, the tar subroutine will add the $option{dest_dir} to each of the files in the @file list. The $options{dest_dir} name is only used for the name stored in the tar archive file and not to access the files from the site storage.

untar

 $success = Archive::TarGzip->untar([@file], \%options or\@options or @options);
 $success = untar([@file], \%options or\@options or @options); # only if imported

The untar subroutine extracts directories and files from a tar archive file. The untar subroutine does not assume that the directories are stored in the correct order so that they will be present as needed to create the files.

The name of the file is $option{tar_file}. If tar subroutine that cannot find the $option{tar_file}, it will look for file with the .tar or .tar.gz extension (uses the $option{compress} to determine which one).

If the $option{dest_dir} is present, the tar subroutine will change to the $option{dest_dir} before extracting the files from the tar archive file. The subroutine will restore the original directory after processing.

If the @file list is present or the @{$option{extract_file}} list is present, the untar subroutine will extract only the files in these lists.

If the @{$option{exclude_file}} list is present, the untar subroutine will not extract files in this list.

new

 $tar = new Archive::TarGzip( );
 $tar = new Archive::TarGzip( $filename or filehandle, [$compress]);

 $tar = new Archive::TarGzip( \%options or\@options);

The new method creates a new tar object. The Archive::TarGzip::new method is the only methods that hides a Archive::Tar method with the same name.

The new method passes $filename and $compress inputs to the Archive::Tar::new method which will read the entire tar archive file into memory.

The new method with the $filename is better when using only the Archive::TarGzip methods.

OPEN

 $tar_handle = $tar->taropen( $tar_file, $compress, [\%options or\@options]);

The taropen method opens a $tar_file without bringing any of the files into memory.

If $options{tar_flag} is '>', the taropen method creats a new $tar_file; otherwise, it opens the $tar_file for reading.

PRINT

 $success = $tar->taradd($file_name, $file_contents);

The taradd method appends $file_contents using the name $file_name to the end of the tar archive file taropen for writing. If $file_contents is undefined, the taradd method will use the contents from the file $file_name.

The tarwrite method will remove the first file in the Archive::Tar memory and append it to the end of the tar archive file taropen for writing.

The tarwrite method uses the $option{compress} to decide whether use gzip compress or normal writing of the tar archive file.

READLINE

 \%tar_header = $tar->tarread(@file, [\%options or\@options]);
 \%tar_header = $tar->tarread(\%options or\@options);

The tarread method reads the next file from the tar archive file taropen for reading. The tar file header and file contents are returned in the %tar_header hash along with other information needed for processing by the Archive::Tar and Archive::TarGzip classes.

If the $option{header_only} exists the tarread method skips the file contents and it is not return in the %tar_header.

If either the @file or the @{$option{extract_files}} list is present, the tarread method will check to see if the file is in either of these lists. If the file name is not in the @files list or the @{$option{extract_files}} list, the tarread method will set the $tar_header{skip_file} key and all other %tar_header keys are indetermined.

If the @{$option{exclude_files}} list is present, the tarread method will check to see if the file is in this list. If the file name is in the list, the tarread method will set the $tar_header{skip_file} key and all other %tar_header keys are indetermined.

If the tarread method reaches the end of the tar archive file, it will set the $tar_header{end_of_tar} key and all other %tar_header keys are indermeined.

The $tar_header keys are as follows:

 name
 mode
 uid
 gid
 size
 mtime
 chksum
 typeflag
 linkname
 magic
 version
 uname
 gname
 devmajor
 devminor
 prefix
 error
 end_of_tar
 header_only
 skip_file
 data
 file_position

target

 $status = $tar->target( \$buffer, $size);

The target method gets bytes in 512 byte chunks from the tar archive file taropen for reading. If \$buffer is undefined, the target method skips over the $size bytes and any additional bytes to pad out to 512 byte boundaries.

The target method uses the $option{compress} to decide whether use gzip uncompress or normal reading of the tar archive file.

CLOSE

 $success = $tar->CLOSE( );

This closes the tar archive opened by the OPEN subroutine.

parse_header

 \%tar_header = Archive::TarGzip->parse_header($buffer) ;
 \%tar_header = parse_header($buffer);  # only if imported

The parse_header subroutine takes the pack 512 byte tar file header and parses it into a the Archive::Tar header hash with a few additional hash keys. This is the return for the READLINE subroutine.

REQUIREMENTS ^

Someday

DEMONSTRATION ^

 #########
 # perl TarGzip.d
 ###

~~~~~~ Demonstration overview ~~~~~

The results from executing the Perl Code follow on the next lines as comments. For example,

 2 + 2
 # 4

~~~~~~ The demonstration follows ~~~~~

     use File::Package;
     use File::AnySpec;
     use File::SmartNL;
     use File::Spec;
     use File::Path;

     my $fp = 'File::Package';
     my $snl = 'File::SmartNL';
     my $uut = 'Archive::TarGzip'; # Unit Under Test
     my $loaded;

 ##################
 # Load UUT
 # 

 my $errors = $fp->load_package($uut)
 $errors

 # ''
 #
      my @files = qw(
          lib/Data/Str2Num.pm
          lib/Docs/Site_SVD/Data_Str2Num.pm
          Makefile.PL
          MANIFEST
          README
          t/Data/Str2Num.d
          t/Data/Str2Num.pm
          t/Data/Str2Num.t
      );
      my $file;
      foreach $file (@files) {
          $file = File::AnySpec->fspec2os( 'Unix', $file );
      }
      my $src_dir = File::Spec->catdir('TarGzip', 'expected');

     unlink 'TarGzip.tar.gz';
     rmtree (File::Spec->catfile('TarGzip', 'Data-Str2Num-0.02'));

 ##################
 # tar files into compressed archive
 # 

 Archive::TarGzip->tar( @files, {tar_file => 'TarGzip.tar.gz', src_dir  => $src_dir,
             dest_dir => 'Data-Str2Num-0.02', compress => 1} )

 # 'TarGzip.tar.gz'
 #

 ##################
 # Untar compressed archive
 # 

 Archive::TarGzip->untar( {dest_dir=>'TarGzip', tar_file=>'TarGzip.tar.gz', compress => 1, umask => 0} )

 # 1
 #
 $snl->fin(File::Spec->catfile('TarGzip', 'Data-Str2Num-0.02', 'MANIFEST'))

 # 'lib/Docs/Site_SVD/Data_Str2Num.pm
 #MANIFEST
 #Makefile.PL
 #README
 #lib/Data/Str2Num.pm
 #t/Data/Str2Num.d
 #t/Data/Str2Num.pm
 #t/Data/Str2Num.t'
 #
 $snl->fin(File::Spec->catfile('TarGzip', 'expected', 'MANIFEST'))

 # 'lib/Docs/Site_SVD/Data_Str2Num.pm
 #MANIFEST
 #Makefile.PL
 #README
 #lib/Data/Str2Num.pm
 #t/Data/Str2Num.d
 #t/Data/Str2Num.pm
 #t/Data/Str2Num.t'
 #

QUALITY ASSURANCE ^

Running the test script TarGzip.t verifies the requirements for this module. The tmake.pl cover script for Test::STDmaker automatically generated the TarGzip.t test script, TarGzip.d demo script, and t::Archive::TarGzip Software Test Description (STD) program module POD, from the t::Archive::TarGzip program module contents. The tmake.pl cover script automatically ran the TarGzip.d demo script and inserted the results into the 'DEMONSTRATION' section above. The t::Tie::TarGzip program module is in the distribution file Archive-TarGzip-$VERSION.tar.gz. =head1 NOTES

Author

The holder of the copyright and maintainer is

< support@SoftwareDiamonds.com >

Copyright Notice

Copyrighted (c) 2002 Software Diamonds

All Rights Reserved

Binding Requirements Notice

Binding requirements are indexed with the

pharse 'shall[dd]' where dd is an unique number for each header section. This conforms to standard federal government practices, 490A 3.2.3.6. In accordance with the License for 'Tie::Gzip', Software Diamonds is not liable for meeting any requirement, binding or otherwise.

License

Software Diamonds permits the redistribution and use in source and binary forms, with or without modification, provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Commercial installation of the binary or source must visually present to the installer the above copyright notice, this list of conditions intact, that the original source is available at http://softwarediamonds.com and provide means for the installer to actively accept the list of conditions; otherwise, a license fee must be paid to Softwareware Diamonds.

SOFTWARE DIAMONDS, http://www.softwarediamonds.com, PROVIDES THIS SOFTWARE 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWARE DIAMONDS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING USE OF THIS SOFTWARE, EVEN IF ADVISED OF NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE POSSIBILITY OF SUCH DAMAGE.

SEE ALSO ^

Docs::Site_SVD::Archive_TarGzip
Test::STDmaker
Archive::Tar
syntax highlighting: