{
    "mode": "perldoc",
    "parameter": "Archive::Zip::FAQ",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Archive%3A%3AZip%3A%3AFAQ/json",
    "generated": "2026-06-10T13:42:52Z",
    "sections": {
        "NAME": {
            "content": "Archive::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "It seems that I keep answering the same questions over and over again. I assume that this is\nbecause my documentation is deficient, rather than that people don't read the documentation.\n\nSo this FAQ is an attempt to cut down on the number of personal answers I have to give. At least\nI can now say \"You *did* read the FAQ, right?\".\n\nThe questions are not in any particular order. The answers assume the current version of\nArchive::Zip; some of the answers depend on newly added/fixed functionality.\n",
            "subsections": []
        },
        "Install problems on RedHat 8 or 9 with Perl 5.8.0": {
            "content": "Q: Archive::Zip won't install on my RedHat 9 system! It's broke!\n\nA: This has become something of a FAQ. Basically, RedHat broke some versions of Perl by setting\nLANG to UTF8. They apparently have a fixed version out as an update.\n\nYou might try running CPAN or creating your Makefile after exporting the LANG environment\nvariable as\n\n\"LANG=C\"\n\n<https://bugzilla.redhat.com/bugzilla/showbug.cgi?id=87682>\n\nWhy is my zip file so big?\nQ: My zip file is actually bigger than what I stored in it! Why?\n\nA: Some things to make sure of:\n\nMake sure that you are requesting COMPRESSIONDEFLATED if you are storing strings.\n$member->desiredCompressionMethod( COMPRESSIONDEFLATED );\n\nDon't make lots of little files if you can help it.\nSince zip computes the compression tables for each member, small members without much\nentropy won't compress well. Instead, if you've got lots of repeated strings in your data,\ntry to combine them into one big member.\n\nMake sure that you are requesting COMPRESSIONSTORED if you are storing things that are already\ncompressed.\nIf you're storing a .zip, .jpg, .mp3, or other compressed file in a zip, then don't compress\nthem again. They'll get bigger.\n\nSample code?\nQ: Can you send me code to do (whatever)?\n\nA: Have you looked in the \"examples/\" directory yet? It contains:\n\nexamples/calcSizes.pl -- How to find out how big a Zip file will be before writing it\nexamples/copy.pl -- Copies one Zip file to another\nexamples/extract.pl -- extract file(s) from a Zip\nexamples/mailZip.pl -- make and mail a zip file\nexamples/mfh.pl -- demo for use of MockFileHandle\nexamples/readScalar.pl -- shows how to use IO::Scalar as the source of a Zip read\nexamples/selfex.pl -- a brief example of a self-extracting Zip\nexamples/unzipAll.pl -- uses Archive::Zip::Tree to unzip an entire Zip\nexamples/updateZip.pl -- shows how to read/modify/write a Zip\nexamples/updateTree.pl -- shows how to update a Zip in place\nexamples/writeScalar.pl -- shows how to use IO::Scalar as the destination of a Zip write\nexamples/writeScalar2.pl -- shows how to use IO::String as the destination of a Zip write\nexamples/zip.pl -- Constructs a Zip file\nexamples/zipcheck.pl -- One way to check a Zip file for validity\nexamples/zipinfo.pl -- Prints out information about a Zip archive file\nexamples/zipGrep.pl -- Searches for text in Zip files\nexamples/ziptest.pl -- Lists a Zip file and checks member CRCs\nexamples/ziprecent.pl -- Puts recent files into a zipfile\nexamples/ziptest.pl -- Another way to check a Zip file for validity\n",
            "subsections": []
        },
        "Can't Read/modify/write same Zip file": {
            "content": "Q: Why can't I open a Zip file, add a member, and write it back? I get an error message when I\ntry.\n\nA: Because Archive::Zip doesn't (and can't, generally) read file contents into memory, the\noriginal Zip file is required to stay around until the writing of the new file is completed.\n\nThe best way to do this is to write the Zip to a temporary file and then rename the temporary\nfile to have the old name (possibly after deleting the old one).\n\nArchive::Zip v1.02 added the archive methods \"overwrite()\" and \"overwriteAs()\" to do this simply\nand carefully.\n\nSee \"examples/updateZip.pl\" for an example of this technique.\n",
            "subsections": []
        },
        "File creation time not set": {
            "content": "Q: Upon extracting files, I see that their modification (and access) times are set to the time\nin the Zip archive. However, their creation time is not set to the same time. Why?\n\nA: Mostly because Perl doesn't give cross-platform access to *creation time*. Indeed, many\nsystems (like Unix) don't support such a concept. However, if yours does, you can easily set it.\nGet the modification time from the member using \"lastModTime()\".\n",
            "subsections": []
        },
        "Can't use Archive::Zip on gzip files": {
            "content": "Q: Can I use Archive::Zip to extract Unix gzip files?\n\nA: No.\n\nThere is a distinction between Unix gzip files, and Zip archives that also can use the gzip\ncompression.\n\nDepending on the format of the gzip file, you can use Compress::Raw::Zlib, or Archive::Tar to\ndecompress it (and de-archive it in the case of Tar files).\n\nYou can unzip PKZIP/WinZip/etc/ archives using Archive::Zip (that's what it's for) as long as\nany compressed members are compressed using Deflate compression.\n",
            "subsections": []
        },
        "Add a directory/tree to a Zip": {
            "content": "Q: How can I add a directory (or tree) full of files to a Zip?\n\nA: You can use the Archive::Zip::addTree*() methods:\n\nuse Archive::Zip;\nmy $zip = Archive::Zip->new();\n# add all readable files and directories below . as xyz/*\n$zip->addTree( '.', 'xyz' );\n# add all readable plain files below /abc as def/*\n$zip->addTree( '/abc', 'def', sub { -f && -r } );\n# add all .c files below /tmp as stuff/*\n$zip->addTreeMatching( '/tmp', 'stuff', '\\.c$' );\n# add all .o files below /tmp as stuff/* if they aren't writable\n$zip->addTreeMatching( '/tmp', 'stuff', '\\.o$', sub { ! -w } );\n# add all .so files below /tmp that are smaller than 200 bytes as stuff/*\n$zip->addTreeMatching( '/tmp', 'stuff', '\\.o$', sub { -s < 200 } );\n# and write them into a file\n$zip->writeToFileNamed('xxx.zip');\n",
            "subsections": []
        },
        "Extract a directory/tree": {
            "content": "Q: How can I extract some (or all) files from a Zip into a different directory?\n\nA: You can use the Archive::Zip::extractTree() method: ??? ||\n\n# now extract the same files into /tmpx\n$zip->extractTree( 'stuff', '/tmpx' );\n",
            "subsections": []
        },
        "Update a directory/tree": {
            "content": "Q: How can I update a Zip from a directory tree, adding or replacing only the newer files?\n\nA: You can use the Archive::Zip::updateTree() method that was added in version 1.09.\n",
            "subsections": []
        },
        "Zip times might be off by 1 second": {
            "content": "Q: It bothers me greatly that my file times are wrong by one second about half the time. Why\ndon't you do something about it?\n\nA: Get over it. This is a result of the Zip format storing times in DOS format, which has a\nresolution of only two seconds.\n",
            "subsections": []
        },
        "Zip times don't include time zone information": {
            "content": "Q: My file times don't respect time zones. What gives?\n\nA: If this is important to you, please submit patches to read the various Extra Fields that\nencode times with time zones. I'm just using the DOS Date/Time, which doesn't have a time zone.\n",
            "subsections": []
        },
        "How do I make a self-extracting Zip": {
            "content": "Q: I want to make a self-extracting Zip file. Can I do this?\n\nA: Yes. You can write a self-extracting archive stub (that is, a version of unzip) to the output\nfilehandle that you pass to writeToFileHandle(). See examples/selfex.pl for how to write a\nself-extracting archive.\n\nHowever, you should understand that this will only work on one kind of platform (the one for\nwhich the stub was compiled).\n",
            "subsections": []
        },
        "How can I deal with Zips with prepended garbage (i.e. from Sircam)": {
            "content": "Q: How can I tell if a Zip has been damaged by adding garbage to the beginning or inside the\nfile?\n\nA: I added code for this for the Amavis virus scanner. You can query archives for their\n'eocdOffset' property, which should be 0:\n\nif ($zip->eocdOffset > 0)\n{ warn($zip->eocdOffset . \" bytes of garbage at beginning or within Zip\") }\n\nWhen members are extracted, this offset will be used to adjust the start of the member if\nnecessary.\n",
            "subsections": []
        },
        "Can't extract Shrunk files": {
            "content": "Q: I'm trying to extract a file out of a Zip produced by PKZIP, and keep getting this error\nmessage:\n\nerror: Unsupported compression combination: read 6, write 0\n\nA: You can't uncompress this archive member. Archive::Zip only supports uncompressed members,\nand compressed members that are compressed using the compression supported by\nCompress::Raw::Zlib. That means only Deflated and Stored members.\n\nYour file is compressed using the Shrink format, which is not supported by Compress::Raw::Zlib.\n\nYou could, perhaps, use a command-line UnZip program (like the Info-Zip one) to extract this.\n",
            "subsections": []
        },
        "Can't do decryption": {
            "content": "Q: How do I decrypt encrypted Zip members?\n\nA: With some other program or library. Archive::Zip doesn't support decryption, and probably\nnever will (unless *you* write it).\n\nHow to test file integrity?\nQ: How can Archive::Zip can test the validity of a Zip file?\n\nA: If you try to decompress the file, the gzip streams will report errors if you have garbage.\nMost of the time.\n\nIf you try to open the file and a central directory structure can't be found, an error will be\nreported.\n\nWhen a file is being read, if we can't find a proper PK.. signature in the right places we\nreport a format error.\n\nIf there is added garbage at the beginning of a Zip file (as inserted by some viruses), you can\nfind out about it, but Archive::Zip will ignore it, and you can still use the archive. When it\ngets written back out the added stuff will be gone.\n\nThere are two ready-to-use utilities in the examples directory that can be used to test file\nintegrity, or that you can use as examples for your own code:\n\nexamples/zipcheck.pl shows how to use an attempted extraction to test a file.\nexamples/ziptest.pl shows how to test CRCs in a file.\n\nDuplicate files in Zip?\nQ: Archive::Zip let me put the same file in my Zip twice! Why don't you prevent this?\n\nA: As far as I can tell, this is not disallowed by the Zip spec. If you think it's a bad idea,\ncheck for it yourself:\n\n$zip->addFile($someFile, $someName) unless $zip->memberNamed($someName);\n\nI can even imagine cases where this might be useful (for instance, multiple versions of files).\n",
            "subsections": []
        },
        "File ownership/permissions/ACLS/etc": {
            "content": "Q: Why doesn't Archive::Zip deal with file ownership, ACLs, etc.?\n\nA: There is no standard way to represent these in the Zip file format. If you want to send me\ncode to properly handle the various extra fields that have been used to represent these through\nthe years, I'll look at it.\n\nI can't compile but ActiveState only has an old version of Archive::Zip\nQ: I've only installed modules using ActiveState's PPM program and repository. But they have a\nmuch older version of Archive::Zip than is in CPAN. Will you send me a newer PPM?\n\nA: Probably not, unless I get lots of extra time. But there's no reason you can't install the\nversion from CPAN. Archive::Zip is pure Perl, so all you need is NMAKE, which you can get for\nfree from Microsoft (see the FAQ in the ActiveState documentation for details on how to install\nCPAN modules).\n\nMy JPEGs (or MP3's) don't compress when I put them into Zips!\nQ: How come my JPEGs and MP3's don't compress much when I put them into Zips?\n\nA: Because they're already compressed.\n",
            "subsections": []
        },
        "Under Windows, things lock up/get damaged": {
            "content": "Q: I'm using Windows. When I try to use Archive::Zip, my machine locks up/makes funny\nsounds/displays a BSOD/corrupts data. How can I fix this?\n\nA: First, try the newest version of Compress::Raw::Zlib. I know of Windows-related problems\nprior to v1.14 of that library.\n",
            "subsections": []
        },
        "Zip contents in a scalar": {
            "content": "Q: I want to read a Zip file from (or write one to) a scalar variable instead of a file. How can\nI do this?\n\nA: Use \"IO::String\" and the \"readFromFileHandle()\" and \"writeToFileHandle()\" methods. See\n\"examples/readScalar.pl\" and \"examples/writeScalar.pl\".\n",
            "subsections": []
        },
        "Reading from streams": {
            "content": "Q: How do I read from a stream (like for the Info-Zip \"funzip\" program)?\n\nA: This is not currently supported, though writing to a stream is.\n",
            "subsections": []
        }
    },
    "summary": "Archive::Zip::FAQ - Answers to a few frequently asked questions about Archive::Zip",
    "flags": [],
    "examples": [],
    "see_also": []
}