faq.html

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

HTML
391
字号
<?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::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip</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__',3);</script>
<h1><a>Archive::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#install_problems_on_redhat_8_or_9_with_perl_5_8_0">Install problems on RedHat 8 or 9 with Perl 5.8.0</a></li>
	<li><a href="#why_is_my_zip_file_so_big">Why is my zip file so big?</a></li>
	<li><a href="#sample_code">Sample code?</a></li>
	<li><a href="#can_t_read_modify_write_same_zip_file">Can't Read/modify/write same Zip file</a></li>
	<li><a href="#file_creation_time_not_set">File creation time not set</a></li>
	<li><a href="#can_t_use_archive__zip_on_gzip_files">Can't use Archive::Zip on gzip files</a></li>
	<li><a href="#add_a_directory_tree_to_a_zip">Add a directory/tree to a Zip</a></li>
	<li><a href="#extract_a_directory_tree">Extract a directory/tree</a></li>
	<li><a href="#update_a_directory_tree">Update a directory/tree</a></li>
	<li><a href="#zip_times_might_be_off_by_1_second">Zip times might be off by 1 second</a></li>
	<li><a href="#zip_times_don_t_include_time_zone_information">Zip times don't include time zone information</a></li>
	<li><a href="#how_do_i_make_a_selfextracting_zip">How do I make a self-extracting Zip</a></li>
	<li><a href="#how_can_i_deal_with_zips_with_prepended_garbage__i_e__from_sircam_">How can I deal with Zips with prepended garbage (i.e. from Sircam)</a></li>
	<li><a href="#can_t_extract_shrunk_files">Can't extract Shrunk files</a></li>
	<li><a href="#can_t_do_decryption">Can't do decryption</a></li>
	<li><a href="#how_to_test_file_integrity">How to test file integrity?</a></li>
	<li><a href="#duplicate_files_in_zip">Duplicate files in Zip?</a></li>
	<li><a href="#file_ownership_permissions_acls_etc">File ownership/permissions/ACLS/etc</a></li>
	<li><a href="#i_can_t_compile_but_activestate_only_has_an_old_version_of_archive__zip">I can't compile but ActiveState only has an old version of Archive::Zip</a></li>
	<li><a href="#my_jpegs__or_mp3_s__don_t_compress_when_i_put_them_into_zips_">My JPEGs (or MP3's) don't compress when I put them into Zips!</a></li>
	<li><a href="#under_windows__things_lock_up_get_damaged">Under Windows, things lock up/get damaged</a></li>
	<li><a href="#zip_contents_in_a_scalar">Zip contents in a scalar</a></li>
	<li><a href="#reading_from_streams">Reading from streams</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Archive::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>It seems that I keep answering the same questions over and over again. I
assume that this is because my documentation is deficient, rather than that
people don't read the documentation.</p>
<p>So this FAQ is an attempt to cut down on the number of personal answers I have
to give. At least I can now say &quot;You <em>did</em> read the FAQ, right?&quot;.</p>
<p>The questions are not in any particular order. The answers assume the current
version of Archive::Zip; some of the answers depend on newly added/fixed
functionality.</p>
<p>
</p>
<hr />
<h1><a name="install_problems_on_redhat_8_or_9_with_perl_5_8_0">Install problems on RedHat 8 or 9 with Perl 5.8.0</a></h1>
<p><strong>Q:</strong> Archive::Zip won't install on my RedHat 9 system! It's broke!</p>
<p><strong>A:</strong> This has become something of a FAQ.
Basically, RedHat broke some versions of Perl by setting LANG to UTF8.
They apparently have a fixed version out as an update.</p>
<p>You might try running CPAN or creating your Makefile after exporting the LANG
environment variable as</p>
<p><code>LANG=C</code></p>
<p><a href="https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=87682">https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=87682</a></p>
<p>
</p>
<hr />
<h1><a name="why_is_my_zip_file_so_big">Why is my zip file so big?</a></h1>
<p><strong>Q:</strong> My zip file is actually bigger than what I stored in it! Why?</p>
<p><strong>A:</strong> Some things to make sure of:</p>
<dl>
<dt><strong><a name="item_make_sure_that_you_are_requesting_compression_defl">Make sure that you are requesting COMPRESSION_DEFLATED if you are storing strings.</a></strong>

<dd>
<p>$member-&gt;desiredCompressionMethod( COMPRESSION_DEFLATED );</p>
</dd>
</li>
<dt><strong><a name="item_don_27t_make_lots_of_little_files_if_you_can_help_">Don't make lots of little files if you can help it.</a></strong>

<dd>
<p>Since zip computes the compression tables for each member, small
members without much entropy won't compress well.  Instead, if you've
got lots of repeated strings in your data, try to combine them into
one big member.</p>
</dd>
</li>
<dt><strong><a name="item_make_sure_that_you_are_requesting_compression_stor">Make sure that you are requesting COMPRESSION_STORED if you are storing things that are already compressed.</a></strong>

<dd>
<p>If you're storing a .zip, .jpg, .mp3, or other compressed file in a zip,
then don't compress them again. They'll get bigger.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="sample_code">Sample code?</a></h1>
<p><strong>Q:</strong> Can you send me code to do (whatever)?</p>
<p><strong>A:</strong> Have you looked in the <code>examples/</code> directory yet? It contains:</p>
<dl>
<dt><strong><a name="item_examples_2fcalcsizes_2epl__2d_2d_how_to_find_out_h">examples/calcSizes.pl    -- How to find out how big a Zip file will be before writing it</a></strong>

<dt><strong><a name="item_examples_2fcopy_2epl__2d_2d_copies_one_zip_file_to">examples/copy.pl         -- Copies one Zip file to another</a></strong>

<dt><strong><a name="item_file">examples/extract.pl      -- extract <code>file(s)</code> from a Zip</a></strong>

<dt><strong><a name="item_examples_2fmailzip_2epl__2d_2d_make_and_mail_a_zip">examples/mailZip.pl      -- make and mail a zip file</a></strong>

<dt><strong><a name="item_examples_2fmfh_2epl__2d_2d_demo_for_use_of_mockfil">examples/mfh.pl          -- demo for use of MockFileHandle</a></strong>

<dt><strong><a name="item_examples_2freadscalar_2epl__2d_2d_shows_how_to_use">examples/readScalar.pl   -- shows how to use IO::Scalar as the source of a Zip read</a></strong>

<dt><strong><a name="item_examples_2fselfex_2epl__2d_2d_a_brief_example_of_a">examples/selfex.pl       -- a brief example of a self-extracting Zip</a></strong>

<dt><strong><a name="item_examples_2funzipall_2epl__2d_2d_uses_archive_3a_3a">examples/unzipAll.pl     -- uses Archive::Zip::Tree to unzip an entire Zip</a></strong>

<dt><strong><a name="item_examples_2fupdatezip_2epl__2d_2d_shows_how_to_read">examples/updateZip.pl    -- shows how to read/modify/write a Zip</a></strong>

<dt><strong><a name="item_examples_2fupdatetree_2epl__2d_2d_shows_how_to_upd">examples/updateTree.pl   -- shows how to update a Zip in place</a></strong>

<dt><strong><a name="item_examples_2fwritescalar_2epl__2d_2d_shows_how_to_us">examples/writeScalar.pl  -- shows how to use IO::Scalar as the destination of a Zip write</a></strong>

<dt><strong><a name="item_examples_2fwritescalar2_2epl__2d_2d_shows_how_to_u">examples/writeScalar2.pl -- shows how to use IO::String as the destination of a Zip write</a></strong>

<dt><strong><a name="item_examples_2fzip_2epl__2d_2d_constructs_a_zip_file">examples/zip.pl          -- Constructs a Zip file</a></strong>

<dt><strong><a name="item_examples_2fzipcheck_2epl__2d_2d_one_way_to_check_a">examples/zipcheck.pl     -- One way to check a Zip file for validity</a></strong>

<dt><strong><a name="item_examples_2fzipinfo_2epl__2d_2d_prints_out_informat">examples/zipinfo.pl      -- Prints out information about a Zip archive file</a></strong>

<dt><strong><a name="item_examples_2fzipgrep_2epl__2d_2d_searches_for_text_i">examples/zipGrep.pl      -- Searches for text in Zip files</a></strong>

<dt><strong><a name="item_examples_2fziptest_2epl__2d_2d_lists_a_zip_file_an">examples/ziptest.pl      -- Lists a Zip file and checks member CRCs</a></strong>

<dt><strong><a name="item_examples_2fziprecent_2epl__2d_2d_puts_recent_files">examples/ziprecent.pl    -- Puts recent files into a zipfile</a></strong>

<dt><strong><a name="item_examples_2fziptest_2epl__2d_2d_another_way_to_chec">examples/ziptest.pl      -- Another way to check a Zip file for validity</a></strong>

</dl>
<p>
</p>
<hr />
<h1><a name="can_t_read_modify_write_same_zip_file">Can't Read/modify/write same Zip file</a></h1>
<p><strong>Q:</strong> Why can't I open a Zip file, add a member, and write it back? I get an
error message when I try.</p>
<p><strong>A:</strong> Because Archive::Zip doesn't (and can't, generally) read file contents into memory,
the original Zip file is required to stay around until the writing of the new
file is completed.</p>
<p>The best way to do this is to write the Zip to a temporary file and then
rename the temporary file to have the old name (possibly after deleting the
old one).</p>
<p>Archive::Zip v1.02 added the archive methods <code>overwrite()</code> and
<code>overwriteAs()</code> to do this simply and carefully.</p>
<p>See <code>examples/updateZip.pl</code> for an example of this technique.</p>
<p>
</p>
<hr />
<h1><a name="file_creation_time_not_set">File creation time not set</a></h1>
<p><strong>Q:</strong> Upon extracting files, I see that their modification (and access) times are
set to the time in the Zip archive. However, their creation time is not set to
the same time. Why?</p>
<p><strong>A:</strong> Mostly because Perl doesn't give cross-platform access to <em>creation time</em>.
Indeed, many systems (like Unix) don't support such a concept.
However, if yours does, you can easily set it. Get the modification time from
the member using <code>lastModTime()</code>.</p>
<p>
</p>
<hr />
<h1><a name="can_t_use_archive__zip_on_gzip_files">Can't use Archive::Zip on gzip files</a></h1>
<p><strong>Q:</strong> Can I use Archive::Zip to extract Unix gzip files?</p>
<p><strong>A:</strong> No.</p>
<p>There is a distinction between Unix gzip files, and Zip archives that 
also can use the gzip compression.</p>
<p>Depending on the format of the gzip file, you can use <a href="../../../lib/Compress/Zlib.html">the Compress::Zlib manpage</a>, or
<a href="../../../lib/Archive/Tar.html">the Archive::Tar manpage</a> to decompress it (and de-archive it in the case of Tar files).</p>
<p>You can unzip PKZIP/WinZip/etc/ archives using Archive::Zip (that's what 
it's for) as long as any compressed members are compressed using 

⌨️ 快捷键说明

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