|
|
| limit | Do not read more than limit files. This is useful if you have very big archives, and are only interested in the first few files. |
| extract | If set to true, immediately extract entries when reading them. This gives you the same memory break as the extract_archive function. Note however that entries will not be read into memory, but written straight to disk. |
Returns the number of files read in scalar context, and a list of Archive::Tar::File objects in list context.
Check if the archive contains a certain file. It will return true if the file is in the archive, false otherwise.Note however, that this function does an exact match using eq on the full path. So it cannot compensate for case-insensitive file- systems or compare 2 paths to see if they would point to the same underlying file.
Write files whose names are equivalent to any of the names in @filenames to disk, creating subdirectories as necessary. This might not work too well under VMS. Under MacPerl, the files 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 its 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.
Returns a list of filenames extracted.
Write an entry, whose name is equivalent to the file name provided to disk. Optionally takes a second parameter, which is the full (unix) path (including filename) the entry will be written to.For example:
$tar->extract_file( name/in/archive, name/i/want/to/give/it );
$tar->extract_file( $at_file_object, name/i/want/to/give/it );Returns true on success, false on failure.
Returns a list of the names of all the files in the archive.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, making it equivalent to calling list_files without arguments.
Returns the Archive::Tar::File objects matching the filenames provided. If no filename list was passed, all Archive::Tar::File objects in the current Tar object are returned.Please refer to the Archive::Tar::File documentation on how to handle these objects.
Return the content of the named file.
Make the string $content be the content for the file named $file.
Rename the file of the in-memory archive to $new_name.Note that you must specify a Unix path for $new_name, since per tar standard, all files in the archive must be Unix paths.
Returns true on success and false on failure.
Removes any entries with names matching any of the given filenames from the in-memory archive. Returns a list of Archive::Tar::File objects that remain.
clear clears the current in-memory archive. This effectively gives you a blank object, ready to be filled again. Note that clear only has effect on the object, not the underlying tarfile.
Write the in-memory archive to disk. The first argument can either be the name of a file or a reference to an already open filehandle (a GLOB reference). If the second argument is true, the module will use IO::Zlib to write the file in a compressed format. If IO::Zlib is not available, the write method will fail and return.Note that when you pass in a filehandle, the compression argument is ignored, as all files are printed verbatim to your filehandle. If you wish to enable compression with filehandles, use an IO::Zlib filehandle instead.
Specific levels of compression can be chosen by passing the values 2 through 9 as the second parameter.
The third argument is an optional prefix. All files will be tucked away in the directory you specify as prefix. So if you have files a and b in your archive, and you specify foo as prefix, they will be written to the archive as foo/a and foo/b.
If no arguments are given, write returns the entire formatted archive as a string, which could be useful if youd like to stuff the archive into a socket or a pipe to gzip or something.
Takes a list of filenames and adds them to the in-memory archive.The path to the file is automatically converted to a Unix like equivalent for use in the archive, and, if on MacOS, the files modification time is converted from the MacOS epoch to the Unix epoch. So tar archives created on MacOS with Archive::Tar can be read both with tar on Unix and applications like suntar or Stuffit Expander on MacOS.
Be aware that the files type/creator and resource fork will be lost, which is usually what you want in cross-platform archives.
Returns a list of Archive::Tar::File objects that were just added.
Takes a filename, a scalar full of data and optionally a reference to a hash with specific options.Will add a file to the in-memory archive, with name $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, type. (On MacOS, the files path and modification times are converted to Unix equivalents.)
Valid values for the file type are the following constants defined in Archive::Tar::Constants:
Returns the Archive::Tar::File object that was just added, or undef on failure.
FILE Regular file. HARDLINK SYMLINK Hard and symbolic (soft) links; linkname should specify target. CHARDEV BLOCKDEV Character and block devices. devmajor and devminor should specify the major and minor device numbers. DIR Directory. FIFO FIFO (named pipe). SOCKET Socket.
Returns the current errorstring (usually, the last error reported). If a true value was specified, it will give the Carp::longmess equivalent of the error, in effect giving you a stacktrace.For backwards compatibility, this error is also available as $Archive::Tar::error although it is much recommended you use the method call instead.
Archive::Tar needs to know the current directory, and it will run Cwd::cwd() every time it extracts a relative entry from the tarfile and saves it in the file system. (As of version 1.30, however, Archive::Tar will use the speed optimization described below automatically, so its only relevant if youre using extract_file()).Since Archive::Tar doesnt change the current directory internally while it is extracting the items in a tarball, all calls to Cwd::cwd() can be avoided if we can guarantee that the current directory doesnt get changed externally.
To use this performance boost, set the current directory via
use Cwd; $tar->setcwd( cwd() );once before calling a function like extract_file and Archive::Tar will use the current directory setting from then on and wont call Cwd::cwd() internally.
To switch back to the default behaviour, use
$tar->setcwd( undef );and Archive::Tar will call Cwd::cwd() internally again.
If youre using Archive::Tars exract() method, setcwd() will be called for you.
Returns true if we currently have IO::String support loaded.Either IO::String or perlio support is needed to support writing stringified archives. Currently, perlio is the preferred method, if available.
See the GLOBAL VARIABLES section to see how to change this preference.
Returns true if we currently have perlio support loaded.This requires perl-5.8 or higher, compiled with perlio
Either IO::String or perlio support is needed to support writing stringified archives. Currently, perlio is the preferred method, if available.
See the GLOBAL VARIABLES section to see how to change this preference.
Creates a tar file from the list of files provided. The first argument can either be the name of the tar file to create or a reference to an open file handle (e.g. a GLOB reference).The second argument specifies the level of compression to be used, if any. Compression of tar files requires the installation of the IO::Zlib module. Specific levels of 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.
Note that when you pass in a filehandle, the compression argument is ignored, as all files are printed verbatim to your filehandle. If you wish to enable compression with filehandles, use an IO::Zlib filehandle instead.
The remaining arguments list the files to be included in the tar file. These files must all exist. Any files which dont exist or cant be read are silently ignored.
If the archive creation fails for any reason, create_archive will return false. Please use the error method to find the cause of the failure.
Note that this method does not write on the fly as it were; it still reads all the files into memory before writing out the archive. Consult the FAQ below if this is a problem.
Returns a list of the names of all the files in the archive. The first argument can either be the name of the tar file to list or a reference to an open file handle (e.g. a GLOB reference).If list_archive() is passed an array reference as its third argument it returns a list of hash references containing the requested properties of each file. The following list of properties is supported: full_path, name, size, mtime (last modified date), mode, uid, gid, linkname, uname, gname, devmajor, devminor, prefix.
See Archive::Tar::File for details about supported properties.
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.
Extracts the contents of the tar file. The first argument can either be the name of the tar file to create or a reference to an open file handle (e.g. a GLOB reference). All relative paths in the tar file will be created underneath the current working directory.extract_archive will return a list of files it extracted. If the archive extraction fails for any reason, extract_archive will return false. Please use the error method to find the cause of the failure.
A simple checking routine, which will return true if Archive::Tar is able to uncompress compressed archives on the fly with IO::Zlib, or false if IO::Zlib is not installed.You can use this as a shortcut to determine whether Archive::Tar will do what you think before passing compressed archives to its read method.
Set this variable to 1 to make Archive::Tar effectively make a copy of the file when extracting. Default is 0, which means the symlink stays intact. Of course, you will have to pack the file linked to as well.This option is checked when you write out the tarfile using write or create_archive.
This works just like /bin/tars -h option.
By default, Archive::Tar will try to chown your files if it is able to. In some cases, this may not be desired. In that case, set this variable to 0 to disable chown-ing, even if it were possible.The default is 1.
By default, Archive::Tar will try to chmod your files to whatever mode was specified for the particular file in the archive. In some cases, this may not be desired. In that case, set this variable to 0 to disable chmod-ing.The default is 1.
By default, Archive::Tar will try to put paths that are over 100 characters in the prefix field of your tar header, as defined per POSIX-standard. However, some (older) tar programs do not implement this spec. To retain compatibility with these older or non-POSIX compliant versions, you can set the $DO_NOT_USE_PREFIX variable to a true value, and Archive::Tar will use an alternate way of dealing with paths over 100 characters by using the GNU Extended Header feature.Note that clients who do not support the GNU Extended Header feature will not be able to read these archives. Such clients include tars on Solaris, Irix and AIX.
The default is 0.
Set this variable to 1 to always get the Carp::longmess output of the warnings, instead of the regular carp. This is the same message you would get by doing:
$tar->error(1);Defaults to 0.
Set this variable to 0 if you do not want any warnings printed. Personally I recommend against doing this, but people asked for the option. Also, be advised that this is of course not threadsafe.Defaults to 1.
Holds the last reported error. Kept for historical reasons, but its use is very much discouraged. Use the error() method instead:
warn $tar->error unless $tar->extract;
This variable holds a boolean indicating if we currently have perlio support loaded. This will be enabled for any perl greater than 5.8 compiled with perlio.If you feel strongly about disabling it, set this variable to false. Note that you will then need IO::String installed to support writing stringified archives.
Dont change this variable unless you really know what youre doing.
This variable holds a boolean indicating if we currently have IO::String support loaded. This will be enabled for any perl that has a loadable IO::String module.If you feel strongly about disabling it, set this variable to false. Note that you will then need perlio support from your perl to be able to write stringified archives.
Dont change this variable unless you really know what youre doing.
Whats the minimum perl version required to run Archive::Tar? You will need perl version 5.005_03 or newer. Isnt Archive::Tar slow? Yes it is. Its pure perl, so its a lot slower then your /bin/tar However, its very portable. If speed is an issue, consider using /bin/tar instead. Isnt Archive::Tar heavier on memory than /bin/tar? Yes it is, see previous answer. Since Compress::Zlib and therefore IO::Zlib doesnt support seek on their filehandles, there is little choice but to read the archive into memory. This is ok if you want to do in-memory manipulation of the archive. If you just want to extract, use the extract_archive class method instead. It will optimize and write to disk immediately. Cant you lazy-load data instead? No, not easily. See previous question. How much memory will an X kb tar file need? Probably more than X kb, since it will all be read into memory. If this is a problem, and you dont need to do in memory manipulation of the archive, consider using /bin/tar instead. What do you do with unsupported filetypes in an archive? Unix has a few filetypes that arent supported on other platforms, like Win32. If we encounter a hardlink or symlink well just try to make a copy of the original file, rather than throwing an error. This does require you to read the entire archive in to memory first, since otherwise we wouldnt know what data to fill the copy with. (This means that you cannot use the class methods on archives that have incompatible filetypes and still expect things to work).
For other filetypes, like chardevs and blockdevs well warn that the extraction of this particular item didnt work.
Im using WinZip, or some other non-POSIX client, and files are not being extracted properly! By default, Archive::Tar is in a completely POSIX-compatible mode, which uses the POSIX-specification of tar to store files. For paths greather than 100 characters, this is done using the POSIX header prefix. Non-POSIX-compatible clients may not support this part of the specification, and may only support the GNU Extended Header functionality. To facilitate those clients, you can set the $Archive::Tar::DO_NOT_USE_PREFIX variable to true. See the GLOBAL VARIABLES section for details on this variable. How do I extract only files that have property X from an archive? Sometimes, you might not wish to extract a complete archive, just the files that are relevant to you, based on some criteria. You can do this by filtering a list of Archive::Tar::File objects based on your criteria. For example, to extract only files that have the string foo in their title, you would use:
$tar->extract( grep { $_->full_path =~ /foo/ } $tar->get_files );This way, you can filter on any attribute of the files in the archive. Consult the Archive::Tar::File documentation on how to use these objects.
How do I access .tar.Z files? The Archive::Tar module can optionally use Compress::Zlib (via the IO::Zlib module) to access tar files that have been compressed with gzip. Unfortunately tar files compressed with the Unix compress utility cannot be read by Compress::Zlib and so cannot be directly accesses by Archive::Tar. If the uncompress or gunzip programs are available, you can use one of these workarounds to read .tar.Z files from Archive::Tar
Firstly with uncompress
use Archive::Tar;
open F, "uncompress -c $filename |"; my $tar = Archive::Tar->new(*F); ...and this with gunzip
use Archive::Tar;
open F, "gunzip -c $filename |"; my $tar = Archive::Tar->new(*F); ...Similarly, if the compress program is available, you can use this to write a .tar.Z file
use Archive::Tar; use IO::File;
my $fh = new IO::File "| compress -c >$filename"; my $tar = Archive::Tar->new(); ... $tar->write($fh); $fh->close ;
Check if passed in handles are open for read/write Currently I dont know of any portable pure perl way to do this. Suggestions welcome. Allow archives to be passed in as string Currently, we only allow opened filehandles or filenames, but not strings. The internals would need some reworking to facilitate stringified archives. Facilitate processing an opened filehandle of a compressed archive Currently, we only support this if the filehandle is an IO::Zlib object. Environments, like apache, will present you with an opened filehandle to an uploaded file, which might be a compressed archive.
The GNU tar specification http://www.gnu.org/software/tar/manual/tar.html The PAX format specication The specifcation which tar derives from; http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html A comparison of GNU and POSIX tar standards; http://www.delorie.com/gnu/docs/tar/tar_114.html GNU tar intends to switch to POSIX compatibility GNU Tar authors have expressed their intention to become completely POSIX-compatible; http://www.gnu.org/software/tar/manual/html_node/Formats.html A Comparison between various tar implementations Lists known issues and incompatibilities; http://gd.tuwien.ac.at/utils/archivers/star/README.otherbugs
This module by Jos Boumans <kane@cpan.org>.
Thanks to Sean Burke, Chris Nandor, Chip Salzenberg, Tim Heaney and especially Andrew Savige for their help and suggestions.
This module is copyright (c) 2002 Jos Boumans <kane@cpan.org>. All rights reserved.This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
| perl v5.8.7 | Archive::Tar (3) | 2006-08-01 |
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.