tar.html

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

HTML
814 行
字号
<code>perlio</code> support loaded. This will be enabled for any perl
greater than <code>5.8</code> compiled with <code>perlio</code>.</p>
<p>If you feel strongly about disabling it, set this variable to
<code>false</code>. Note that you will then need <code>IO::String</code> installed
to support writing stringified archives.</p>
<p>Don't change this variable unless you <strong>really</strong> know what you're
doing.</p>
<p>
</p>
<h2><a name="_archive__tar__has_io_string">$Archive::Tar::HAS_IO_STRING</a></h2>
<p>This variable holds a boolean indicating if we currently have 
<code>IO::String</code> support loaded. This will be enabled for any perl
that has a loadable <code>IO::String</code> module.</p>
<p>If you feel strongly about disabling it, set this variable to
<code>false</code>. Note that you will then need <code>perlio</code> support from
your perl to be able to  write stringified archives.</p>
<p>Don't change this variable unless you <strong>really</strong> know what you're
doing.</p>
<p>
</p>
<hr />
<h1><a name="faq">FAQ</a></h1>
<dl>
<dt><strong><a name="item_what_27s_the_minimum_perl_version_required_to_run_">What's the minimum perl version required to run Archive::Tar?</a></strong>

<dd>
<p>You will need perl version 5.005_03 or newer.</p>
</dd>
</li>
<dt><strong><a name="item_isn_27t_archive_3a_3atar_slow_3f">Isn't Archive::Tar slow?</a></strong>

<dd>
<p>Yes it is. It's pure perl, so it's a lot slower then your <code>/bin/tar</code>
However, it's very portable. If speed is an issue, consider using
<code>/bin/tar</code> instead.</p>
</dd>
</li>
<dt><strong><a name="item_isn_27t_archive_3a_3atar_heavier_on_memory_than__2">Isn't Archive::Tar heavier on memory than /bin/tar?</a></strong>

<dd>
<p>Yes it is, see previous answer. Since <code>Compress::Zlib</code> and therefore
<code>IO::Zlib</code> doesn't support <a href="../../lib/Pod/perlfunc.html#item_seek"><code>seek</code></a> 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 <code>extract_archive</code> class method
instead. It will optimize and write to disk immediately.</p>
</dd>
</li>
<dt><strong><a name="item_can_27t_you_lazy_2dload_data_instead_3f">Can't you lazy-load data instead?</a></strong>

<dd>
<p>No, not easily. See previous question.</p>
</dd>
</li>
<dt><strong><a name="item_how_much_memory_will_an_x_kb_tar_file_need_3f">How much memory will an X kb tar file need?</a></strong>

<dd>
<p>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 <code>/bin/tar</code> instead.</p>
</dd>
</li>
<dt><strong><a name="item_what_do_you_do_with_unsupported_filetypes_in_an_ar">What do you do with unsupported filetypes in an archive?</a></strong>

<dd>
<p><code>Unix</code> has a few filetypes that aren't supported on other platforms,
like <code>Win32</code>. If we encounter a <code>hardlink</code> or <a href="../../lib/Pod/perlfunc.html#item_symlink"><code>symlink</code></a> we'll just
try to make a copy of the original file, rather than throwing an error.</p>
</dd>
<dd>
<p>This does require you to read the entire archive in to memory first,
since otherwise we wouldn't 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).</p>
</dd>
<dd>
<p>For other filetypes, like <code>chardevs</code> and <code>blockdevs</code> we'll warn that
the extraction of this particular item didn't work.</p>
</dd>
</li>
<dt><strong><a name="item_i_27m_using_winzip_2c_or_some_other_non_2dposix_cl">I'm using WinZip, or some other non-POSIX client, and files are not being extracted properly!</a></strong>

<dd>
<p>By default, <code>Archive::Tar</code> is in a completely POSIX-compatible
mode, which uses the POSIX-specification of <code>tar</code> to store files.
For paths greather than 100 characters, this is done using the
<code>POSIX header prefix</code>. Non-POSIX-compatible clients may not support
this part of the specification, and may only support the <code>GNU Extended
Header</code> functionality. To facilitate those clients, you can set the
<code>$Archive::Tar::DO_NOT_USE_PREFIX</code> variable to <code>true</code>. See the 
<code>GLOBAL VARIABLES</code> section for details on this variable.</p>
</dd>
</li>
<dt><strong><a name="item_how_do_i_extract_only_files_that_have_property_x_f">How do I extract only files that have property X from an archive?</a></strong>

<dd>
<p>Sometimes, you might not wish to extract a complete archive, just
the files that are relevant to you, based on some criteria.</p>
</dd>
<dd>
<p>You can do this by filtering a list of <code>Archive::Tar::File</code> objects
based on your criteria. For example, to extract only files that have
the string <code>foo</code> in their title, you would use:</p>
</dd>
<dd>
<pre>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">extract</span><span class="operator">(</span> 
        <span class="keyword">grep</span> <span class="operator">{</span> <span class="variable">$_</span><span class="operator">-&gt;</span><span class="variable">full_path</span> <span class="operator">=~</span> <span class="regex">/foo/</span> <span class="operator">}</span> <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="variable">get_files</span>
    <span class="operator">);</span>
</pre>
</dd>
<dd>
<p>This way, you can filter on any attribute of the files in the archive.
Consult the <code>Archive::Tar::File</code> documentation on how to use these
objects.</p>
</dd>
</li>
<dt><strong><a name="item_how_do_i_access__2etar_2ez_files_3f">How do I access .tar.Z files?</a></strong>

<dd>
<p>The <code>Archive::Tar</code> module can optionally use <code>Compress::Zlib</code> (via
the <code>IO::Zlib</code> module) to access tar files that have been compressed
with <code>gzip</code>. Unfortunately tar files compressed with the Unix <code>compress</code>
utility cannot be read by <code>Compress::Zlib</code> and so cannot be directly
accesses by <code>Archive::Tar</code>.</p>
</dd>
<dd>
<p>If the <code>uncompress</code> or <code>gunzip</code> programs are available, you can use
one of these workarounds to read <code>.tar.Z</code> files from <code>Archive::Tar</code></p>
</dd>
<dd>
<p>Firstly with <code>uncompress</code></p>
</dd>
<dd>
<pre>
    <span class="keyword">use</span> <span class="variable">Archive::Tar</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<pre>
    <span class="keyword">open</span> <span class="variable">F</span><span class="operator">,</span> <span class="string">"uncompress -c $filename |"</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><span class="variable">*F</span><span class="operator">);</span>
    <span class="operator">...</span>
</pre>
</dd>
<dd>
<p>and this with <code>gunzip</code></p>
</dd>
<dd>
<pre>
    <span class="keyword">use</span> <span class="variable">Archive::Tar</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<pre>
    <span class="keyword">open</span> <span class="variable">F</span><span class="operator">,</span> <span class="string">"gunzip -c $filename |"</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><span class="variable">*F</span><span class="operator">);</span>
    <span class="operator">...</span>
</pre>
</dd>
<dd>
<p>Similarly, if the <code>compress</code> program is available, you can use this to
write a <code>.tar.Z</code> file</p>
</dd>
<dd>
<pre>
    <span class="keyword">use</span> <span class="variable">Archive::Tar</span><span class="operator">;</span>
    <span class="keyword">use</span> <span class="variable">IO::File</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<pre>
    <span class="keyword">my</span> <span class="variable">$fh</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">IO::File</span> <span class="string">"| compress -c &gt;$filename"</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>
    <span class="operator">...</span>
    <span class="variable">$tar</span><span class="operator">-&gt;</span><span class="keyword">write</span><span class="operator">(</span><span class="variable">$fh</span><span class="operator">);</span>
    <span class="variable">$fh</span><span class="operator">-&gt;</span><span class="keyword">close</span> <span class="operator">;</span>
</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="todo">TODO</a></h1>
<dl>
<dt><strong><a name="item_check_if_passed_in_handles_are_open_for_read_2fwri">Check if passed in handles are open for read/write</a></strong>

<dd>
<p>Currently I don't know of any portable pure perl way to do this.
Suggestions welcome.</p>
</dd>
</li>
<dt><strong><a name="item_allow_archives_to_be_passed_in_as_string">Allow archives to be passed in as string</a></strong>

<dd>
<p>Currently, we only allow opened filehandles or filenames, but
not strings. The internals would need some reworking to facilitate
stringified archives.</p>
</dd>
</li>
<dt><strong><a name="item_facilitate_processing_an_opened_filehandle_of_a_co">Facilitate processing an opened filehandle of a compressed archive</a></strong>

<dd>
<p>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.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<dl>
<dt><strong><a name="item_the_gnu_tar_specification">The GNU tar specification</a></strong>

<dd>
<p><code>http://www.gnu.org/software/tar/manual/tar.html</code></p>
</dd>
</li>
<dt><strong><a name="item_the_pax_format_specication">The PAX format specication</a></strong>

<dd>
<p>The specifcation which tar derives from; <code> http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html</code></p>
</dd>
</li>
<dt><strong><a name="item_a_comparison_of_gnu_and_posix_tar_standards_3b_htt">A comparison of GNU and POSIX tar standards; <code>http://www.delorie.com/gnu/docs/tar/tar_114.html</code></a></strong>

<dt><strong><a name="item_gnu_tar_intends_to_switch_to_posix_compatibility">GNU tar intends to switch to POSIX compatibility</a></strong>

<dd>
<p>GNU Tar authors have expressed their intention to become completely
POSIX-compatible; <code>http://www.gnu.org/software/tar/manual/html_node/Formats.html</code></p>
</dd>
</li>
<dt><strong><a name="item_a_comparison_between_various_tar_implementations">A Comparison between various tar implementations</a></strong>

<dd>
<p>Lists known issues and incompatibilities; <code>http://gd.tuwien.ac.at/utils/archivers/star/README.otherbugs</code></p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>This module by
Jos Boumans &lt;<a href="mailto:kane@cpan.org">kane@cpan.org</a>&gt;.</p>
<p>
</p>
<hr />
<h1><a name="acknowledgements">ACKNOWLEDGEMENTS</a></h1>
<p>Thanks to Sean Burke, Chris Nandor, Chip Salzenberg, Tim Heaney and
especially Andrew Savige for their help and suggestions.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>This module is
copyright (c) 2002 Jos Boumans &lt;<a href="mailto:kane@cpan.org">kane@cpan.org</a>&gt;.
All rights reserved.</p>
<p>This library is free software;
you may redistribute and/or modify it under the same
terms as Perl itself.</p>

</body>

</html>

⌨️ 快捷键说明

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