|
Tar - module for manipulation of tar archives. |
Tar - module for manipulation of tar archives.
use Archive::Tar;
Archive::Tar->create_archive ("my.tar.gz", 9, "/this/file", "/that/file");
print join "\n", Archive::Tar->list_archive ("my.tar.gz"), "";
$tar = Archive::Tar->new();
$tar->read("origin.tar.gz",1);
$tar->add_files("file/foo.c", "file/bar.c");
$tar->add_data("file/baz.c","This is the file contents");
$tar->write("files.tar");
This is a module for the handling of tar archives.
Archive::Tar provides an object oriented mechanism for handling tar files. It provides class methods for quick and easy files handling while also allowing for the creation of tar file objects for custom manipulation. If you have the Compress::Zlib module installed, Archive::Tar will also support compressed or gzipped tar files.
The class methods should be sufficient for most tar file interaction.
The second argument specifies the level of compression to be used, if any. Compression of tar files requires the installation of the Compress::Zlib module. Specific levels or compression may be requested by passing a value between 2 and 9 as the second argument. Any other value evaluating as true will result in the default compression level being used.
The remaining arguments list the files to be included in the tar file. These files must all exist. Any files which don\'t exist or can\'t be read are silently ignored.
If the archive creation fails for any reason, create_archive will
return undef. Please use the error method to find the cause of the
failure.
If list_archive() is passed an array reference as its second
argument it returns a list of hash references containing the requested
properties of each file. The following list of properties is
supported: name, size, mtime (last modified date), mode, uid, gid,
linkname, uname, gname, devmajor, devminor, prefix.
Passing an array reference containing only one element, 'name', is special cased to return a list of names rather than a list of hash references.
If the archive extraction fails for any reason, extract_archive
will return undef. Please use the error method to find the cause
of the failure.
new() calls the
read() method automatically, parsing on the arguments provided read().
If new() is invoked with arguments and the read method fails for
any reason, new() returns undef.
The second argument is now optional as Archive::Tar will automatically detect compressed archives.
The read will replace any previous content in $tar!
add_files(@filenamelist)$filename and content $data. Specific
properties can be set using $opthashref, The following list of
properties is supported: name, size, mtime (last modified date), mode,
uid, gid, linkname, uname, gname, devmajor, devminor, prefix. (On
MacOS, the file\'s path and modification times are converted to Unix
equivalents.)
eq.
write method will fail.
Specific levels of compression can be chosen by passing the values 2
through 9 as the second parameter.
If no arguments are given, write returns the entire formatted
archive as a string, which could be useful if you\'d like to stuff the
archive into a socket or a pipe to gzip or something. This
functionality may be deprecated later, however, as you can also do
this using a GLOB reference for the first argument.
extract(@filenames)@filenames to disk, creating subdirectories as necessary. This
might not work too well under VMS. Under MacPerl, the file\'s
modification time will be converted to the MacOS zero of time, and
appropriate conversions will be done to the path. However, the length
of each element of the path is not inspected to see whether it\'s
longer than MacOS currently allows (32 characters).
If extract is called without a list of file names, the entire
contents of the archive are extracted.
list_files()If list_files() is passed an array reference as its first argument
it returns a list of hash references containing the requested
properties of each file. The following list of properties is
supported: name, size, mtime (last modified date), mode, uid, gid,
linkname, uname, gname, devmajor, devminor, prefix.
Passing an array reference containing only one element, 'name', is special cased to return a list of names rather than a list of hash references.
get_content($file)replace_content($file,$content)
data() method.
Added proper support for MacOS. Thanks to Paul J. Schinder <schinder@leprss.gsfc.nasa.gov>.
Arrange to chmod() at the very end in case it makes the file read only.
Win32 is actually picky about that.
SunOS 4.x tar makes tarfiles that contain directory entries that don\'t have typeflag set properly. We use the trailing slash to recognise directories in such tar files.
Fixed two bugs with symlink handling, reported in excellent detail by an admin at teleport.com called Chris.
Primitive tar program (called ptar) included with distribution. Usage should be pretty obvious if you\'ve used a normal tar program.
Added methods get_content and replace_content.
Added support for paths longer than 100 characters, according to POSIX. This is compatible with just about everything except GNU tar. Way to go, GNU tar (use a better tar, or GNU cpio).
NOTE: When adding files to an archive, files with basenames longer than 100 characters will be silently ignored. If the prefix part of a path is longer than 155 characters, only the last 155 characters will be stored.
list_files() method, as requested by Michael Wiedman.
Fixed a couple of dysfunctions when run under Windows NT. Michael Wiedmann reported the bugs.
Changed the documentation to reflect reality a bit better.
Fixed bug in format_tar_entry. Bug reported by Michael Schilli.
use strict; stop complaining under
perl version 5.003.
Ties to the Compress::Zlib manpage put in. Will warn if it isn\'t available.
$tar->write() with no argument now returns the formatted archive.
Protected the calls to readlink() and symlink(). AFAIK this module
should now run just fine on Windows NT.
Add method to write a single entry to disk (extract)
Added method to add entries entirely from scratch (add_data)
Changed name of add() to add_file()
All calls to croak() removed and replaced with returning undef and
setting Tar::error.
Better handling of tarfiles with garbage at the end.
|
Tar - module for manipulation of tar archives. |