📄 archive::tar.3
字号:
Rename the file of the in-memory archive to \f(CW$new_name\fR..PPNote that you must specify a Unix path for \f(CW$new_name\fR, since per tarstandard, all files in the archive must be Unix paths..PPReturns true on success and false on failure..ie n .Sh "$tar\->remove (@filenamelist)".el .Sh "\f(CW$tar\fP\->remove (@filenamelist)".IX Subsection "$tar->remove (@filenamelist)"Removes any entries with names matching any of the given filenamesfrom the in-memory archive. Returns a list of \f(CW\*(C`Archive::Tar::File\*(C'\fRobjects that remain..ie n .Sh "$tar\->clear".el .Sh "\f(CW$tar\fP\->clear".IX Subsection "$tar->clear"\&\f(CW\*(C`clear\*(C'\fR clears the current in-memory archive. This effectively givesyou a 'blank' object, ready to be filled again. Note that \f(CW\*(C`clear\*(C'\fRonly has effect on the object, not the underlying tarfile..ie n .Sh "$tar\fP\->write ( [$file, \f(CW$compressed\fP, \f(CW$prefix] )".el .Sh "\f(CW$tar\fP\->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 eitherbe 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 useIO::Zlib to write the file in a compressed format. If IO::Zlib isnot available, the \f(CW\*(C`write\*(C'\fR method will fail and return..PPNote that when you pass in a filehandle, the compression argumentis ignored, as all files are printed verbatim to your filehandle.If you wish to enable compression with filehandles, use an\&\f(CW\*(C`IO::Zlib\*(C'\fR filehandle instead..PPSpecific levels of compression can be chosen by passing the values 2through 9 as the second parameter..PPThe third argument is an optional prefix. All files will be tuckedaway in the directory you specify as prefix. So if you have files\&'a' and 'b' in your archive, and you specify 'foo' as prefix, theywill be written to the archive as 'foo/a' and 'foo/b'..PPIf no arguments are given, \f(CW\*(C`write\*(C'\fR returns the entire formattedarchive as a string, which could be useful if you'd like to stuff thearchive into a socket or a pipe to gzip or something..ie n .Sh "$tar\fP\->add_files( \f(CW@filenamelist )".el .Sh "\f(CW$tar\fP\->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..PPThe path to the file is automatically converted to a Unix likeequivalent for use in the archive, and, if on MacOS, the file'smodification time is converted from the MacOS epoch to the Unix epoch.So tar archives created on MacOS with \fBArchive::Tar\fR can be readboth with \fItar\fR on Unix and applications like \fIsuntar\fR or\&\fIStuffit Expander\fR on MacOS..PPBe aware that the file's type/creator and resource fork will be lost,which is usually what you want in cross-platform archives..PPReturns a list of \f(CW\*(C`Archive::Tar::File\*(C'\fR objects that were just added..ie n .Sh "$tar\fP\->add_data ( \f(CW$filename\fP, \f(CW$data, [$opthashref] )".el .Sh "\f(CW$tar\fP\->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 toa hash with specific options..PPWill add a file to the in-memory archive, with name \f(CW$filename\fR andcontent \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, type. (On MacOS, the file's path andmodification times are converted to Unix equivalents.).PPValid values for the file type are the following constants defined inArchive::Tar::Constants:.IP "\s-1FILE\s0" 4.IX Item "FILE"Regular file..IP "\s-1HARDLINK\s0" 4.IX Item "HARDLINK".PD 0.IP "\s-1SYMLINK\s0" 4.IX Item "SYMLINK".PDHard and symbolic (\*(L"soft\*(R") links; linkname should specify target..IP "\s-1CHARDEV\s0" 4.IX Item "CHARDEV".PD 0.IP "\s-1BLOCKDEV\s0" 4.IX Item "BLOCKDEV".PDCharacter and block devices. devmajor and devminor should specify the majorand minor device numbers..IP "\s-1DIR\s0" 4.IX Item "DIR"Directory..IP "\s-1FIFO\s0" 4.IX Item "FIFO"\&\s-1FIFO\s0 (named pipe)..IP "\s-1SOCKET\s0" 4.IX Item "SOCKET"Socket..PPReturns the \f(CW\*(C`Archive::Tar::File\*(C'\fR object that was just added, or\&\f(CW\*(C`undef\*(C'\fR on failure..ie n .Sh "$tar\->error( [$BOOL] )".el .Sh "\f(CW$tar\fP\->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'\fRequivalent of the error, in effect giving you a stacktrace..PPFor backwards compatibility, this error is also available as\&\f(CW$Archive::Tar::error\fR although it is much recommended you use themethod call instead..ie n .Sh "$tar\fP\->setcwd( \f(CW$cwd );".el .Sh "\f(CW$tar\fP\->setcwd( \f(CW$cwd\fP );".IX Subsection "$tar->setcwd( $cwd );"\&\f(CW\*(C`Archive::Tar\*(C'\fR needs to know the current directory, and it will run\&\f(CW\*(C`Cwd::cwd()\*(C'\fR \fIevery\fR time it extracts a \fIrelative\fR entry from the tarfile and saves it in the file system. (As of version 1.30, however,\&\f(CW\*(C`Archive::Tar\*(C'\fR will use the speed optimization described below automatically, so it's only relevant if you're using \f(CW\*(C`extract_file()\*(C'\fR)..PPSince \f(CW\*(C`Archive::Tar\*(C'\fR doesn't change the current directory internallywhile it is extracting the items in a tarball, all calls to \f(CW\*(C`Cwd::cwd()\*(C'\fRcan be avoided if we can guarantee that the current directory doesn'tget changed externally..PPTo use this performance boost, set the current directory via.PP.Vb 2\& use Cwd;\& $tar\->setcwd( cwd() );.Ve.PPonce before calling a function like \f(CW\*(C`extract_file\*(C'\fR and\&\f(CW\*(C`Archive::Tar\*(C'\fR will use the current directory setting from then onand won't call \f(CW\*(C`Cwd::cwd()\*(C'\fR internally..PPTo switch back to the default behaviour, use.PP.Vb 1\& $tar\->setcwd( undef );.Ve.PPand \f(CW\*(C`Archive::Tar\*(C'\fR will call \f(CW\*(C`Cwd::cwd()\*(C'\fR internally again..PPIf you're using \f(CW\*(C`Archive::Tar\*(C'\fR's \f(CW\*(C`exract()\*(C'\fR method, \f(CW\*(C`setcwd()\*(C'\fR willbe called for you..ie n .Sh "$bool\fP = \f(CW$tar\->has_io_string".el .Sh "\f(CW$bool\fP = \f(CW$tar\fP\->has_io_string".IX Subsection "$bool = $tar->has_io_string"Returns true if we currently have \f(CW\*(C`IO::String\*(C'\fR support loaded..PPEither \f(CW\*(C`IO::String\*(C'\fR or \f(CW\*(C`perlio\*(C'\fR support is needed to support writing stringified archives. Currently, \f(CW\*(C`perlio\*(C'\fR is the preferred method, ifavailable..PPSee the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR section to see how to change this preference..ie n .Sh "$bool\fP = \f(CW$tar\->has_perlio".el .Sh "\f(CW$bool\fP = \f(CW$tar\fP\->has_perlio".IX Subsection "$bool = $tar->has_perlio"Returns true if we currently have \f(CW\*(C`perlio\*(C'\fR support loaded..PPThis requires \f(CW\*(C`perl\-5.8\*(C'\fR or higher, compiled with \f(CW\*(C`perlio\*(C'\fR.PPEither \f(CW\*(C`IO::String\*(C'\fR or \f(CW\*(C`perlio\*(C'\fR support is needed to support writing stringified archives. Currently, \f(CW\*(C`perlio\*(C'\fR is the preferred method, ifavailable..PPSee the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR section to see how to change this preference..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 firstargument can either be the name of the tar file to create or areference to an open file handle (e.g. a \s-1GLOB\s0 reference)..PPThe second argument specifies the level of compression to be used, ifany. Compression of tar files requires the installation of theIO::Zlib module. Specific levels of compression may berequested by passing a value between 2 and 9 as the second argument.Any other value evaluating as true will result in the defaultcompression level being used..PPNote that when you pass in a filehandle, the compression argumentis ignored, as all files are printed verbatim to your filehandle.If you wish to enable compression with filehandles, use an\&\f(CW\*(C`IO::Zlib\*(C'\fR filehandle instead..PPThe 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 beread are silently ignored..PPIf the archive creation fails for any reason, \f(CW\*(C`create_archive\*(C'\fR willreturn false. Please use the \f(CW\*(C`error\*(C'\fR method to find the cause of thefailure..PPNote that this method does not write \f(CW\*(C`on the fly\*(C'\fR as it were; itstill reads all the files into memory before writing out the archive.Consult the \s-1FAQ\s0 below if this is a problem..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. Thefirst argument can either be the name of the tar file to list or areference to an open file handle (e.g. a \s-1GLOB\s0 reference)..PPIf \f(CW\*(C`list_archive()\*(C'\fR is passed an array reference as its thirdargument it returns a list of hash references containing the requestedproperties of each file. The following list of properties issupported: full_path, name, size, mtime (last modified date), mode, uid, gid, linkname, uname, gname, devmajor, devminor, prefix..PPSee \f(CW\*(C`Archive::Tar::File\*(C'\fR for details about supported properties..PPPassing an array reference containing only one element, 'name', isspecial cased to return a list of names rather than a list of hashreferences..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 eitherbe the name of the tar file to create or a reference to an open filehandle (e.g. a \s-1GLOB\s0 reference). All relative paths in the tar file willbe created underneath the current working directory..PP\&\f(CW\*(C`extract_archive\*(C'\fR will return a list of files it extracted.If the archive extraction fails for any reason, \f(CW\*(C`extract_archive\*(C'\fRwill return false. Please use the \f(CW\*(C`error\*(C'\fR method to find the causeof the failure..Sh "Archive::Tar\->can_handle_compressed_files".IX Subsection "Archive::Tar->can_handle_compressed_files"A simple checking routine, which will return true if \f(CW\*(C`Archive::Tar\*(C'\fRis able to uncompress compressed archives on the fly with \f(CW\*(C`IO::Zlib\*(C'\fR,or false if \f(CW\*(C`IO::Zlib\*(C'\fR is not installed..PPYou can use this as a shortcut to determine whether \f(CW\*(C`Archive::Tar\*(C'\fRwill do what you think before passing compressed archives to its\&\f(CW\*(C`read\*(C'\fR method..SH "GLOBAL VARIABLES".IX Header "GLOBAL VARIABLES".ie n .Sh "$Archive::Tar::FOLLOW_SYMLINK".el .Sh "\f(CW$Archive::Tar::FOLLOW_SYMLINK\fP".IX Subsection "$Archive::Tar::FOLLOW_SYMLINK"Set this variable to \f(CW1\fR to make \f(CW\*(C`Archive::Tar\*(C'\fR effectively make acopy of the file when extracting. Default is \f(CW0\fR, whichmeans the symlink stays intact. Of course, you will have to pack thefile linked to as well..PPThis option is checked when you write out the tarfile using \f(CW\*(C`write\*(C'\fRor \f(CW\*(C`create_archive\*(C'\fR..PPThis works just like \f(CW\*(C`/bin/tar\*(C'\fR's \f(CW\*(C`\-h\*(C'\fR option..ie n .Sh "$Archive::Tar::CHOWN".el .Sh "\f(CW$Archive::Tar::CHOWN\fP".IX Subsection "$Archive::Tar::CHOWN"By default, \f(CW\*(C`Archive::Tar\*(C'\fR will try to \f(CW\*(C`chown\*(C'\fR your files if it isable to. In some cases, this may not be desired. In that case, setthis variable to \f(CW0\fR to disable \f(CW\*(C`chown\*(C'\fR\-ing, even if it werepossible..PPThe default is \f(CW1\fR..ie n .Sh "$Archive::Tar::CHMOD".el .Sh "\f(CW$Archive::Tar::CHMOD\fP".IX Subsection "$Archive::Tar::CHMOD"By default, \f(CW\*(C`Archive::Tar\*(C'\fR will try to \f(CW\*(C`chmod\*(C'\fR your files towhatever mode was specified for the particular file in the archive.In some cases, this may not be desired. In that case, set thisvariable to \f(CW0\fR to disable \f(CW\*(C`chmod\*(C'\fR\-ing..PPThe default is \f(CW1\fR..ie n .Sh "$Archive::Tar::DO_NOT_USE_PREFIX".el .Sh "\f(CW$Archive::Tar::DO_NOT_USE_PREFIX\fP".IX Subsection "$Archive::Tar::DO_NOT_USE_PREFIX"By default, \f(CW\*(C`Archive::Tar\*(C'\fR will try to put paths that are over 100 characters in the \f(CW\*(C`prefix\*(C'\fR field of your tar header, asdefined 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 \f(CW$DO_NOT_USE_PREFIX\fR variable to a true value, and \f(CW\*(C`Archive::Tar\*(C'\fR will use an alternate way of dealing with paths over 100 characters by using the \&\f(CW\*(C`GNU Extended Header\*(C'\fR feature..PPNote that clients who do not support the \f(CW\*(C`GNU Extended Header\*(C'\fRfeature will not be able to read these archives. Such clients includetars on \f(CW\*(C`Solaris\*(C'\fR, \f(CW\*(C`Irix\*(C'\fR and \f(CW\*(C`AIX\*(C'\fR..PPThe default is \f(CW0\fR..ie n .Sh "$Archive::Tar::DEBUG".el .Sh "\f(CW$Archive::Tar::DEBUG\fP".IX Subsection "$Archive::Tar::DEBUG"Set this variable to \f(CW1\fR to always get the \f(CW\*(C`Carp::longmess\*(C'\fR output
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -