tags:

views:

698

answers:

3

I need to create a Zip archive after filtering the list of files I want to include. Preferably I'd like the module to work in both Windows and Linux.

Since I need to filter the list of files, I don't really want to to use an external program. I'd rather not introduce external dependencies either so I can compile the script into a single executable on Windows (using ActiveState PDK).

What I already tried

Until now I've used Archive::Zip found on CPAN but it has a major bug on Windows machine that use non-ASCII filenames: the filenames get corrupted in the archive as they don't get translated into unicode.

There is a bug report filed for that but it hasn't been updated in over 10 months and in the module documentation the developer is rather unhelpful (of the "fix your computer or get rid of Windows" kind).

Update:
Thanks to the clarifications from brian and Alan Haggai Alavi it seems that enough love is being put in Archive::Zip to get these bugs out soon and finally have a fully functioning zip module in Windows.

A: 

You could try the standard-distribution Archive::Extract. It may not be any better than Archive::Zip, but the documentation says that, if there are problems, it goes under the hood to try to use command-line tools on your system to unzip the file. This is probably most robust on Unix, but Windows has a zip archive utility, and it should be accessible via the command line. Plus, Archive::Extract can handle many other types of compression (theoretically).

Of course, it may turn out that Archive::Extract simply figures out what kind of compression the file uses and then passes it to the appropriate other library, which might be Archive::Zip.

You might also try IO::Uncompress::Unzip and it's counterpart, IO::Compress::Zip, for just unzipping, reading, and rezipping. If absolutely necessary. Again, I don't know how much better these will work, but they are all part of the standard library.

Chris Lutz
Archive::Extract isn't any good for creating files.
brian d foy
IO:Compress::Zip doesn't provide the tools for creating an archive containing files and folders. It is used to compress streams and single files, a bit like gzip does.
Renaud Bompuis
+8  A: 

Although the module documentation says some stupid things about Windows, the current maintainer is Adam Kennedy, the same guy who brought you Strawberry Perl. He's definitely not anti-Windows. He released a version October, so they are working on it. There's also an open grant from The Perl Foundation to fix Archive::Extract bugs.The bug you mention, RT 35334: Filename Encoding by Archive::Zip, maybe just needs someone to show it some love. That could be you. People solve the problems that bother them, so maybe nobody interested in the module needs this just yet.

The module has had problems, and I've been following its progress since I use it in a couple projects. It has gotten a lot better recently and can certainly use some love. Sometimes open source means helping to fix the problems that you encounter. I know this doesn't help you solve your problem immediately, but that's how I think you're going to get this done aside from system() calls.

brian d foy
Thanks for the details Brian. I got the source and was going through it last night to see if I could hack something to get utf8 support. Then Alan Haggai Alavi dropped by to confirm this was already done and available soon, so I'll wait and see.
Renaud Bompuis
+5  A: 

The above said bug has been solved very lately by the addition of Unicode filename support under Windows. A release featuring the fix will be available in CPAN within a week.

Alan Haggai Alavi
Hi Alan. Thanks for the update. I was looking at the source for v1.27_01 to see if I could hack it but I'm glad a more official version will be available soon.Thanks for your work on this module.
Renaud Bompuis
If you can, please update the FAQ to remove the rather unbecoming comment about Windows. That sort of thing doesn't help and it does disservice to Perl which is targeted to all OS.
Renaud Bompuis
Hi Renaud,Thank you for the remark. I will be sure to update the FAQ as well as the POD of the module.Regards.
Alan Haggai Alavi