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, \@options)
$success = untar(@options)
$success = untar(\%options)
$success = untar(\@options)
$success = untar(@file, \%options)
$success = untar(@file, \@options)
\%tar_header = parse_header($buffer)
######
# Class Interface
#
use Archive::TarGzip
use vars qw(@ISA)
@ISA = qw(Archive::TarGzip)
$tar_file = __PACkAGE__->tar(@file, \%options)
$tar_file = __PACkAGE__->tar(@file, \@options)
$success = __PACkAGE__->untar(@options)
$success = __PACkAGE__->untar(\%options)
$success = __PACkAGE__->untar(\@options)
$success = __PACkAGE__->untar(@file, \%options)
$success = __PACkAGE__->untar(@file, \@options)
\%tar_header = __PACkAGE__->parse_header($buffer)
######
# Object Interface
#
use Archive::TarGzip;
$tar = new Archive::TarGip( )
$tar = new Archive::TarGip( \%options )
$tar = new Archive::TarGip( \@options )
$tar = new Archive::TarGip( $filename or \*filehandle, \%options )
$tar = new Archive::TarGip( $filename or \*filehandle, \@options )
$tar = new Archive::TarGip( $filename or \*filehandle, $compress, @options)
$tar_handle = $tar->taropen( $tar_file, $compress, [\%options or\@options])
$success = $tar->taradd($file_name, $file_contents)
$success = $tar->tarwrite()
\%tar_header = $tar->tarread(\%options)
\%tar_header = $tar->tarread(\@options)
\%tar_header = $tar->tarread(@file, \%options)
\%tar_header = $tar->tarread(@file, \@options)
$status = $tar->target( \$buffer, $size)
$success = $tar->tarclose()
DESCRIPTION
The Archive::TarGzip module provides tar subroutine to archive a list of files in an archive file in the tar format. The archve 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 is dervided from its parent Archive::Tar class. The new methods supplied with the Archive::TarGzip derived class 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. The new methods provide a smaller memory footprint that enhances performance for very large archive files.
Individual descriptions of the mehods and subroutines follows.
- tar subroutine
-
$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 subroutine
-
$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 method
-
$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.
- taropen method
-
$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.
- taradd method
-
$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.
- tarwrite method
-
$success = $tar->tarwrite();
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.
- tarread method
-
\%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 method
-
$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.
- tarclose method
-
$success = $tar->tarclose();
This closes the tar achive opened by the taropen method.
- parse_header subroutine
-
\%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 thetarget method
.
REQUIREMENTS
The requirements are coming.
DEMONSTRATION
~~~~~~ Demonstration overview ~~~~~
Perl code begins with the prompt
=>
The selected results from executing the Perl Code follow on the next lines. For example,
=> 2 + 2
4
~~~~~~ The demonstration follows ~~~~~
=> use File::Package;
=> use File::AnySpec;
=> use File::SmartNL;
=> use File::Spec;
=> my $fp = 'File::Package';
=> my $snl = 'File::SmartNL';
=> my $uut = 'Archive::TarGzip'; # Unit Under Test
=> my $loaded;
=> 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');
=> Archive::TarGzip->tar( @files, {tar_file => 'TarGzip.tar.gz', src_dir => $src_dir,
=> dest_dir => 'Data-Str2Num-0.02', compress => 1} )
'TarGzip.tar.gz'
=> Archive::TarGzip->untar( dest_dir=>'TarGzip', tar_file=>'TarGzip.tar.gz', compress => 1)
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 'Gzip.t' found in the "Archive-TarGzip-$VERSION.tar.gz" distribution file verifies the requirements for this module.
All testing software and documentation stems from the Software Test Description (STD) program module 't::Archive::TarGzip', found in the distribution file "Archive-TarGzip-$VERSION.tar.gz".
The 't::Archive::TarGzip' STD POD contains a tracebility matix between the requirements established above for this module, and the test steps identified by a 'ok' number from running the 'Gzip.t' test script.
The t::Archive::TarGzip' STD program module '__DATA__' section contains the data to perform the following:
to generate the test script 'Gzip.t'
generate the tailored STD POD in the 't::Archive::TarGzip' module,
generate the 'Gzip.d' demo script,
replace the POD demonstration section herein with the demo script 'Gzip.d' output, and
run the test script using Test::Harness with or without the verbose option,
To perform all the above, prepare and run the automation software as follows:
Install "Test_STDmaker-$VERSION.tar.gz" from one of the respositories only if it has not been installed:
http://www.softwarediamonds/packages/
http://www.perl.com/CPAN-local/authors/id/S/SO/SOFTDIA/
manually place the script tmake.pl in "Test_STDmaker-$VERSION.tar.gz' in the site operating system executable path only if it is not in the executable path
place the 't::Archive::TarGzip' at the same level in the directory struture as the directory holding the 'Tie::Gzip' module
execute the following in any directory:
tmake -test_verbose -replace -run -pm=t::Archive::TarGzip
NOTES
FILES
The installation of the "Archive-TarGzip-$VERSION.tar.gz" distribution file installs the 'Docs::Site_SVD::Archive_TarGzip' SVD program module.
The __DATA__ data section of the 'Docs::Site_SVD::Archive_TarGzip' contains all the necessary data to generate the POD section of 'Docs::Site_SVD::Archive_TarGzip' and the "Archive-TarGzip-$VERSION.tar.gz" distribution file.
To make use of the 'Docs::Site_SVD::Archive_TarGzip' SVD program module, perform the following:
install "ExtUtils-SVDmaker-$VERSION.tar.gz" from one of the respositories only if it has not been installed:
http://www.softwarediamonds/packages/
http://www.perl.com/CPAN-local/authors/id/S/SO/SOFTDIA/
manually place the script vmake.pl in "ExtUtils-SVDmaker-$VERSION.tar.gz' in the site operating system executable path only if it is not in the executable path
Make any appropriate changes to the __DATA__ section of the 'Docs::Site_SVD::Archive_TarGzip' module. For example, any changes to 'Tie::Gzip' will impact the at least 'Changes' field.
Execute the following:
vmake readme_html all -pm=Docs::Site_SVD::Archive_TarGzip
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 STD490A). In accordance with the License, Software Diamonds is not liable for 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:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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.
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.