.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Archive::Tar 3" .TH Archive::Tar 3 "2003-06-12" "perl v5.8.4" "User Contributed Perl Documentation" .SH "NAME" Archive::Tar \- module for manipulations of tar archives .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Archive::Tar; \& my $tar = Archive::Tar->new; .Ve .PP .Vb 2 \& $tar->read('origin.tgz',1); \& $tar->extract(); .Ve .PP .Vb 2 \& $tar->add_files('file/foo.pl', 'docs/README'); \& $tar->add_data('file/baz.txt', 'This is the contents now'); .Ve .PP .Vb 1 \& $tar->rename('oldname', 'new/file/name'); .Ve .PP .Vb 1 \& $tar->write('files.tar'); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" 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 IO::Zlib module installed, Archive::Tar will also support compressed or gzipped tar files. .PP An object of class Archive::Tar represents a .tar(.gz) archive full of files and things. .SH "Object Methods" .IX Header "Object Methods" .ie n .Sh "Archive::Tar\->new( [$file, $compressed] )" .el .Sh "Archive::Tar\->new( [$file, \f(CW$compressed\fP] )" .IX Subsection "Archive::Tar->new( [$file, $compressed] )" Returns a new Tar object. If given any arguments, \f(CW\*(C`new()\*(C'\fR calls the \&\f(CW\*(C`read()\*(C'\fR method automatically, passing on the arguments provided to the \f(CW\*(C`read()\*(C'\fR method. .PP If \f(CW\*(C`new()\*(C'\fR is invoked with arguments and the \f(CW\*(C`read()\*(C'\fR method fails for any reason, \f(CW\*(C`new()\*(C'\fR returns undef. .ie n .Sh "$tar\->read ( $filename\fP|$handle, \f(CW$compressed, {opt => 'val'} )" .el .Sh "$tar\->read ( \f(CW$filename\fP|$handle, \f(CW$compressed\fP, {opt => 'val'} )" .IX Subsection "$tar->read ( $filename|$handle, $compressed, {opt => 'val'} )" Read the given tar file into memory. The first argument can either be the name of a file or a reference to an already open filehandle (or an IO::Zlib object if it's compressed) The second argument indicates whether the file referenced by the first argument is compressed. .PP The \f(CW\*(C`read\*(C'\fR will \fIreplace\fR any previous content in \f(CW$tar\fR! .PP The second argument may be considered optional if IO::Zlib is installed, since it will transparently Do The Right Thing. Archive::Tar will warn if you try to pass a compressed file if IO::Zlib is not available and simply return. .PP The third argument can be a hash reference with options. Note that all options are case\-sensitive. .IP "limit" 4 .IX Item "limit" Do not read more than \f(CW\*(C`limit\*(C'\fR files. This is usefull if you have very big archives, and are only interested in the first few files. .IP "extract" 4 .IX Item "extract" If set to true, immediately extract entries when reading them. This gives you the same memory break as the \f(CW\*(C`extract_archive\*(C'\fR function. Note however that entries will not be read into memory, but written straight to disk. .PP All files are stored internally as \f(CW\*(C`Archive::Tar::File\*(C'\fR objects. Please consult the Archive::Tar::File documentation for details. .PP Returns the number of files read in scalar context, and a list of \&\f(CW\*(C`Archive::Tar::File\*(C'\fR objects in list context. .Sh "$tar\->extract( [@filenames] )" .IX Subsection "$tar->extract( [@filenames] )" Write files whose names are equivalent to any of the names in \&\f(CW@filenames\fR to disk, creating subdirectories as necessary. This might not work too well under \s-1VMS\s0. 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). .PP If \f(CW\*(C`extract\*(C'\fR is called without a list of file names, the entire contents of the archive are extracted. .PP Returns a list of filenames extracted. .Sh "$tar\->list_files( [\e@properties] )" .IX Subsection "$tar->list_files( [@properties] )" Returns a list of the names of all the files in the archive. .PP If \f(CW\*(C`list_files()\*(C'\fR 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. .PP 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 \f(CW\*(C`list_files\*(C'\fR without arguments. .Sh "$tar\->get_files( [@filenames] )" .IX Subsection "$tar->get_files( [@filenames] )" Returns the \f(CW\*(C`Archive::Tar::File\*(C'\fR objects matching the filenames provided. If no filename list was passed, all \f(CW\*(C`Archive::Tar::File\*(C'\fR objects in the current Tar object are returned. .PP Please refer to the \f(CW\*(C`Archive::Tar::File\*(C'\fR documentation on how to handle these objects .ie n .Sh "$tar\->get_content( $file )" .el .Sh "$tar\->get_content( \f(CW$file\fP )" .IX Subsection "$tar->get_content( $file )" Return the content of the named file. .ie n .Sh "$tar\->replace_content( $file\fP, \f(CW$content )" .el .Sh "$tar\->replace_content( \f(CW$file\fP, \f(CW$content\fP )" .IX Subsection "$tar->replace_content( $file, $content )" Make the string \f(CW$content\fR be the content for the file named \f(CW$file\fR. .ie n .Sh "$tar\->rename( $file\fP, \f(CW$new_name )" .el .Sh "$tar\->rename( \f(CW$file\fP, \f(CW$new_name\fP )" .IX Subsection "$tar->rename( $file, $new_name )" Rename the file of the in-memory archive to \f(CW$new_name\fR. .PP Note that you must specify a Unix path for \f(CW$new_name\fR, since per tar standard, all files in the archive must be Unix paths. .PP Returns true on success and false on failure. .Sh "$tar\->remove (@filenamelist)" .IX Subsection "$tar->remove (@filenamelist)" Removes any entries with names matching any of the given filenames from the in-memory archive. Returns a list of \f(CW\*(C`Archive::Tar::File\*(C'\fR objects that remain. .Sh "$tar\->clear" .IX Subsection "$tar->clear" \&\f(CW\*(C`clear\*(C'\fR clears the current in-memory archive. This effectively gives you a 'blank' object, ready to be filled again. Note that \f(CW\*(C`clear\*(C'\fR only has effect on the object, not the underlying tarfile. .ie n .Sh "$tar\->write ( [$file, $compressed\fP, \f(CW$prefix] )" .el .Sh "$tar\->write ( [$file, \f(CW$compressed\fP, \f(CW$prefix\fP] )" .IX Subsection "$tar->write ( [$file, $compressed, $prefix] )" 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 \&\s-1GLOB\s0 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 \f(CW\*(C`write\*(C'\fR method will fail and return. .PP Specific levels of compression can be chosen by passing the values 2 through 9 as the second parameter. .PP 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'. .PP If no arguments are given, \f(CW\*(C`write\*(C'\fR 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. .ie n .Sh "$tar\->add_files( @filenamelist )" .el .Sh "$tar\->add_files( \f(CW@filenamelist\fP )" .IX Subsection "$tar->add_files( @filenamelist )" Takes a list of filenames and adds them to the in-memory archive. .PP The path to the file is automatically converted to a Unix like equivalent for use in the archive, and, if on MacOs, the file's modification time is converted from the MacOS epoch to the Unix epoch. So tar archives created on MacOS with \fBArchive::Tar\fR can be read both with \fItar\fR on Unix and applications like \fIsuntar\fR or \&\fIStuffit Expander\fR on MacOS. .PP Be aware that the file's type/creator and resource fork will be lost, which is usually what you want in cross-platform archives. .PP Returns a list of \f(CW\*(C`Archive::Tar::File\*(C'\fR objects that were just added. .ie n .Sh "$tar\->add_data ( $filename\fP, \f(CW$data, [$opthashref] )" .el .Sh "$tar\->add_data ( \f(CW$filename\fP, \f(CW$data\fP, [$opthashref] )" .IX Subsection "$tar->add_data ( $filename, $data, [$opthashref] )" Takes a filename, a scalar full of data and optionally a reference to a hash with specific options. .PP Will add a file to the in-memory archive, with name \f(CW$filename\fR and content \f(CW$data\fR. Specific properties can be set using \f(CW$opthashref\fR. 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.) .PP Returns the \f(CW\*(C`Archive::Tar::File\*(C'\fR object that was just added, or \&\f(CW\*(C`undef\*(C'\fR on failure. .Sh "$tar\->error( [$BOOL] )" .IX Subsection "$tar->error( [$BOOL] )" Returns the current errorstring (usually, the last error reported). If a true value was specified, it will give the \f(CW\*(C`Carp::longmess\*(C'\fR equivalent of the error, in effect giving you a stacktrace. .PP For backwards compabillity, this error is also available as \&\f(CW$Archive::Tar::error\fR allthough it is much recommended you use the method call instead. .SH "Class Methods" .IX Header "Class Methods" .ie n .Sh "Archive::Tar\->create_archive($file, $compression\fP, \f(CW@filelist)" .el .Sh "Archive::Tar\->create_archive($file, \f(CW$compression\fP, \f(CW@filelist\fP)" .IX Subsection "Archive::Tar->create_archive($file, $compression, @filelist)" 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 \s-1GLOB\s0 reference). .PP 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 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. .PP The remaining arguments list the files to be included in the tar file. These files must all exist. Any files which don\e't exist or can\e't be read are silently ignored. .PP If the archive creation fails for any reason, \f(CW\*(C`create_archive\*(C'\fR will return. Please use the \f(CW\*(C`error\*(C'\fR method to find the cause of the failure. .ie n .Sh "Archive::Tar\->list_archive ($file, $compressed, [\e@properties])" .el .Sh "Archive::Tar\->list_archive ($file, \f(CW$compressed\fP, [\e@properties])" .IX Subsection "Archive::Tar->list_archive ($file, $compressed, [@properties])" 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 create or a reference to an open file handle (e.g. a \s-1GLOB\s0 reference). .PP If \f(CW\*(C`list_archive()\*(C'\fR 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. .PP 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. .ie n .Sh "Archive::Tar\->extract_archive ($file, $gzip)" .el .Sh "Archive::Tar\->extract_archive ($file, \f(CW$gzip\fP)" .IX Subsection "Archive::Tar->extract_archive ($file, $gzip)" 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 \s-1GLOB\s0 reference). All relative paths in the tar file will be created underneath the current working directory. .PP \&\f(CW\*(C`extract_archive\*(C'\fR will return a list of files it extract. If the archive extraction fails for any reason, \f(CW\*(C`extract_archive\*(C'\fR will return. Please use the \f(CW\*(C`error\*(C'\fR method to find the cause of the failure. .SH "GLOBAL VARIABLES" .IX Header "GLOBAL VARIABLES" .Sh "$Archive::Tar::DEBUG" .IX Subsection "$Archive::Tar::DEBUG" Set this variable to \f(CW1\fR to always get the \f(CW\*(C`Carp::longmess\*(C'\fR output of the warnings, instead of the regular \f(CW\*(C`carp\*(C'\fR. This is the same message you would get by doing: .PP .Vb 1 \& $tar->error(1); .Ve .PP Defaults to \f(CW0\fR. .Sh "$Archive::Tar::WARN" .IX Subsection "$Archive::Tar::WARN" Set this variable to \f(CW0\fR 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. .PP Defaults to \f(CW1\fR. .Sh "$Archive::Tar::error" .IX Subsection "$Archive::Tar::error" Holds the last reported error. Kept for historical reasons, but it's use is very much discouraged. Use the \f(CW\*(C`error()\*(C'\fR method instead: .PP .Vb 1 \& warn $tar->error unless $tar->extract; .Ve .SH "FAQ" .IX Header "FAQ" .IP "What's the minimum perl version required to run Archive::Tar?" 4 .IX Item "What's the minimum perl version required to run Archive::Tar?" You will need perl version 5.005_03 or newer. .IP "Isn't Archive::Tar slow?" 4 .IX Item "Isn't Archive::Tar slow?" Yes it is. It's pure perl, so it's a lot slower then your \f(CW\*(C`/bin/tar\*(C'\fR However, it's very portable. If speed is an issue, consider using \&\f(CW\*(C`/bin/tar\*(C'\fR instead. .IP "Isn't Archive::Tar heavier on memory than /bin/tar?" 4 .IX Item "Isn't Archive::Tar heavier on memory than /bin/tar?" Yes it is, see previous answer. Since \f(CW\*(C`Compress::Zlib\*(C'\fR and therefor \&\f(CW\*(C`IO::Zlib\*(C'\fR doesn't support \f(CW\*(C`seek\*(C'\fR 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 \f(CW\*(C`extract_archive\*(C'\fR class method instead. It will optimize and write to disk immediately. .IP "Can't you lazy-load data instead?" 4 .IX Item "Can't you lazy-load data instead?" No, not easily. See previous question. .IP "How much memory will an X kb tar file need?" 4 .IX Item "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 don't need to do in memory manipulation of the archive, consider using \f(CW\*(C`/bin/tar\*(C'\fR instead. .SH "TODO" .IX Header "TODO" .IP "Check if passed in handles are open for read/write" 4 .IX Item "Check if passed in handles are open for read/write" Currently I don't know of any portable pure perl way to do this. Suggestions welcome. .SH "AUTHOR" .IX Header "AUTHOR" This module by Jos Boumans . .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to Sean Burke, Chris Nandor, Chip Salzenberg and Tim Heaney for their help and suggestions. .SH "COPYRIGHT" .IX Header "COPYRIGHT" This module is copyright (c) 2002 Jos Boumans . All rights reserved. .PP This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.