tar.html

来自「perl教程」· HTML 代码 · 共 814 行 · 第 1/3 页

HTML
814
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Archive::Tar - module for manipulations of tar archives</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>Archive::Tar - module for manipulations of tar archives</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#object_methods">Object Methods</a></li>
	<ul>

		<li><a href="#archive__tar_new____file___compressed___">Archive::Tar-&gt;new( [$file, $compressed] )</a></li>
		<li><a href="#_tar_read____filename__handle___compressed___opt_____val____">$tar-&gt;read ( $filename|$handle, $compressed, {opt =&gt; 'val'} )</a></li>
		<li><a href="#_tar_contains_file___filename__">$tar-&gt;contains_file( $filename )</a></li>
		<li><a href="#_tar_extract____filenames___">$tar-&gt;extract( [@filenames] )</a></li>
		<li><a href="#_tar_extract_file___file____extract_path___">$tar-&gt;extract_file( $file, [$extract_path] )</a></li>
		<li><a href="#_tar_list_files_____properties___">$tar-&gt;list_files( [\@properties] )</a></li>
		<li><a href="#_tar_get_files____filenames___">$tar-&gt;get_files( [@filenames] )</a></li>
		<li><a href="#_tar_get_content___file__">$tar-&gt;get_content( $file )</a></li>
		<li><a href="#_tar_replace_content___file___content__">$tar-&gt;replace_content( $file, $content )</a></li>
		<li><a href="#_tar_rename___file___new_name__">$tar-&gt;rename( $file, $new_name )</a></li>
		<li><a href="#_tar_remove___filenamelist_">$tar-&gt;remove (@filenamelist)</a></li>
		<li><a href="#_tar_clear">$tar-&gt;clear</a></li>
		<li><a href="#_tar_write_____file___compressed___prefix___">$tar-&gt;write ( [$file, $compressed, $prefix] )</a></li>
		<li><a href="#_tar_add_files___filenamelist__">$tar-&gt;add_files( @filenamelist )</a></li>
		<li><a href="#_tar_add_data____filename___data____opthashref___">$tar-&gt;add_data ( $filename, $data, [$opthashref] )</a></li>
		<li><a href="#_tar_error____bool___">$tar-&gt;error( [$BOOL] )</a></li>
		<li><a href="#_tar_setcwd___cwd___">$tar-&gt;setcwd( $cwd );</a></li>
		<li><a href="#_bool____tar_has_io_string">$bool = $tar-&gt;has_io_string</a></li>
		<li><a href="#_bool____tar_has_perlio">$bool = $tar-&gt;has_perlio</a></li>
	</ul>

	<li><a href="#class_methods">Class Methods</a></li>
	<ul>

		<li><a href="#archive__tar_create_archive__file___compression___filelist_">Archive::Tar-&gt;create_archive($file, $compression, @filelist)</a></li>
		<li><a href="#archive__tar_list_archive___file___compressed_____properties__">Archive::Tar-&gt;list_archive ($file, $compressed, [\@properties])</a></li>
		<li><a href="#archive__tar_extract_archive___file___gzip_">Archive::Tar-&gt;extract_archive ($file, $gzip)</a></li>
		<li><a href="#archive__tar_can_handle_compressed_files">Archive::Tar-&gt;can_handle_compressed_files</a></li>
	</ul>

	<li><a href="#global_variables">GLOBAL VARIABLES</a></li>
	<ul>

		<li><a href="#_archive__tar__follow_symlink">$Archive::Tar::FOLLOW_SYMLINK</a></li>
		<li><a href="#_archive__tar__chown">$Archive::Tar::CHOWN</a></li>
		<li><a href="#_archive__tar__chmod">$Archive::Tar::CHMOD</a></li>
		<li><a href="#_archive__tar__do_not_use_prefix">$Archive::Tar::DO_NOT_USE_PREFIX</a></li>
		<li><a href="#_archive__tar__debug">$Archive::Tar::DEBUG</a></li>
		<li><a href="#_archive__tar__warn">$Archive::Tar::WARN</a></li>
		<li><a href="#_archive__tar__error">$Archive::Tar::error</a></li>
		<li><a href="#_archive__tar__has_perlio">$Archive::Tar::HAS_PERLIO</a></li>
		<li><a href="#_archive__tar__has_io_string">$Archive::Tar::HAS_IO_STRING</a></li>
	</ul>

	<li><a href="#faq">FAQ</a></li>
	<li><a href="#todo">TODO</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#acknowledgements">ACKNOWLEDGEMENTS</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Archive::Tar - module for manipulations of tar archives</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
    <span class="keyword">use</span> <span class="variable">Archive::Tar</span><span class="operator">;</span>
    <span class="keyword">my</span> <span class="variable">$tar</span> <span class="operator">=</span> <span class="variable">Archive::Tar</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="keyword">read</span><span class="operator">(</span><span class="string">'origin.tgz'</span><span class="operator">,</span><span class="number">1</span><span class="operator">);</span>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">extract</span><span class="operator">();</span>
</pre>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">add_files</span><span class="operator">(</span><span class="string">'file/foo.pl'</span><span class="operator">,</span> <span class="string">'docs/README'</span><span class="operator">);</span>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">add_data</span><span class="operator">(</span><span class="string">'file/baz.txt'</span><span class="operator">,</span> <span class="string">'This is the contents now'</span><span class="operator">);</span>
</pre>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="keyword">rename</span><span class="operator">(</span><span class="string">'oldname'</span><span class="operator">,</span> <span class="string">'new/file/name'</span><span class="operator">);</span>
</pre>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="keyword">write</span><span class="operator">(</span><span class="string">'files.tar'</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>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.</p>
<p>An object of class Archive::Tar represents a .tar(.gz) archive full
of files and things.</p>
<p>
</p>
<hr />
<h1><a name="object_methods">Object Methods</a></h1>
<p>
</p>
<h2><a name="archive__tar_new____file___compressed___">Archive::Tar-&gt;new( [$file, $compressed] )</a></h2>
<p>Returns a new Tar object. If given any arguments, <code>new()</code> calls the
<a href="../../lib/Pod/perlfunc.html#item_read"><code>read()</code></a> method automatically, passing on the arguments provided to
the <a href="../../lib/Pod/perlfunc.html#item_read"><code>read()</code></a> method.</p>
<p>If <code>new()</code> is invoked with arguments and the <a href="../../lib/Pod/perlfunc.html#item_read"><code>read()</code></a> method fails
for any reason, <code>new()</code> returns undef.</p>
<p>
</p>
<h2><a name="_tar_read____filename__handle___compressed___opt_____val____">$tar-&gt;read ( $filename|$handle, $compressed, {opt =&gt; 'val'} )</a></h2>
<p>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.</p>
<p>The <a href="../../lib/Pod/perlfunc.html#item_read"><code>read</code></a> will <em>replace</em> any previous content in <code>$tar</code>!</p>
<p>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.</p>
<p>Note that you can currently <strong>not</strong> pass a <code>gzip</code> compressed
filehandle, which is not opened with <code>IO::Zlib</code>, nor a string
containing the full archive information (either compressed or
uncompressed). These are worth while features, but not currently
implemented. See the <code>TODO</code> section.</p>
<p>The third argument can be a hash reference with options. Note that
all options are case-sensitive.</p>
<dl>
<dt><strong><a name="item_limit">limit</a></strong>

<dd>
<p>Do not read more than <a href="#item_limit"><code>limit</code></a> files. This is useful if you have
very big archives, and are only interested in the first few files.</p>
</dd>
</li>
<dt><strong><a name="item_extract">extract</a></strong>

<dd>
<p>If set to true, immediately extract entries when reading them. This
gives you the same memory break as the <code>extract_archive</code> function.
Note however that entries will not be read into memory, but written
straight to disk.</p>
</dd>
</li>
</dl>
<p>All files are stored internally as <code>Archive::Tar::File</code> objects.
Please consult the <a href="../../lib/Archive/Tar/File.html">the Archive::Tar::File manpage</a> documentation for details.</p>
<p>Returns the number of files read in scalar context, and a list of
<code>Archive::Tar::File</code> objects in list context.</p>
<p>
</p>
<h2><a name="_tar_contains_file___filename__">$tar-&gt;contains_file( $filename )</a></h2>
<p>Check if the archive contains a certain file.
It will return true if the file is in the archive, false otherwise.</p>
<p>Note however, that this function does an exact match using <code>eq</code>
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.</p>
<p>
</p>
<h2><a name="_tar_extract____filenames___">$tar-&gt;extract( [@filenames] )</a></h2>
<p>Write files whose names are equivalent to any of the names in
<code>@filenames</code> 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).</p>
<p>If <a href="#item_extract"><code>extract</code></a> is called without a list of file names, the entire
contents of the archive are extracted.</p>
<p>Returns a list of filenames extracted.</p>
<p>
</p>
<h2><a name="_tar_extract_file___file____extract_path___">$tar-&gt;extract_file( $file, [$extract_path] )</a></h2>
<p>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.</p>
<p>For example:</p>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">extract_file</span><span class="operator">(</span> <span class="string">'name/in/archive'</span><span class="operator">,</span> <span class="string">'name/i/want/to/give/it'</span> <span class="operator">);</span>
</pre>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">extract_file</span><span class="operator">(</span> <span class="variable">$at_file_object</span><span class="operator">,</span>   <span class="string">'name/i/want/to/give/it'</span> <span class="operator">);</span>
</pre>
<p>Returns true on success, false on failure.</p>
<p>
</p>
<h2><a name="_tar_list_files_____properties___">$tar-&gt;list_files( [\@properties] )</a></h2>
<p>Returns a list of the names of all the files in the archive.</p>
<p>If <code>list_files()</code> 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.</p>
<p>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 <code>list_files</code> without
arguments.</p>
<p>
</p>
<h2><a name="_tar_get_files____filenames___">$tar-&gt;get_files( [@filenames] )</a></h2>
<p>Returns the <code>Archive::Tar::File</code> objects matching the filenames
provided. If no filename list was passed, all <code>Archive::Tar::File</code>
objects in the current Tar object are returned.</p>
<p>Please refer to the <code>Archive::Tar::File</code> documentation on how to
handle these objects.</p>
<p>
</p>
<h2><a name="_tar_get_content___file__">$tar-&gt;get_content( $file )</a></h2>
<p>Return the content of the named file.</p>
<p>
</p>
<h2><a name="_tar_replace_content___file___content__">$tar-&gt;replace_content( $file, $content )</a></h2>
<p>Make the string $content be the content for the file named $file.</p>
<p>
</p>
<h2><a name="_tar_rename___file___new_name__">$tar-&gt;rename( $file, $new_name )</a></h2>
<p>Rename the file of the in-memory archive to $new_name.</p>
<p>Note that you must specify a Unix path for $new_name, since per tar
standard, all files in the archive must be Unix paths.</p>
<p>Returns true on success and false on failure.</p>
<p>
</p>
<h2><a name="_tar_remove___filenamelist_">$tar-&gt;remove (@filenamelist)</a></h2>
<p>Removes any entries with names matching any of the given filenames
from the in-memory archive. Returns a list of <code>Archive::Tar::File</code>
objects that remain.</p>
<p>
</p>
<h2><a name="_tar_clear">$tar-&gt;clear</a></h2>
<p><code>clear</code> clears the current in-memory archive. This effectively gives
you a 'blank' object, ready to be filled again. Note that <code>clear</code>
only has effect on the object, not the underlying tarfile.</p>
<p>
</p>
<h2><a name="_tar_write_____file___compressed___prefix___">$tar-&gt;write ( [$file, $compressed, $prefix] )</a></h2>
<p>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 <a href="../../lib/Pod/perlfunc.html#item_write"><code>write</code></a> method will fail and return.</p>
<p>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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?