Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract a compressed archive in Perl?

I need to allow users to upload a zip file via a web form. The server is running Linux with an Apache web server. Are there advantages to using a module like Archive::Zip to extract this archive or should I just execute a system call to unzip with backticks?

like image 293
cowgod Avatar asked Nov 03 '09 16:11

cowgod


People also ask

How do I extract a zip file in Perl?

Say you have a zip file, file1. zip , that only contains a single member, you can read it and write the uncompressed data to the file file1. txt like this. use strict ; use warnings ; use IO::Uncompress::Unzip qw(unzip $UnzipError) ; my $input = "file1.

How do I extract data from a zip file?

To unzip filesOpen File Explorer and find the zipped folder. To unzip the entire folder, right-click to select Extract All, and then follow the instructions. To unzip a single file or folder, double-click the zipped folder to open it. Then, drag or copy the item from the zipped folder to a new location.


1 Answers

According to the Archive::Zip documentation you'd be better off using Archive::Extract:

If you are just going to be extracting zips (and/or other archives) you are recommended to look at using Archive::Extract instead, as it is much easier to use and factors out archive-specific functionality.

That's interesting because Archive::Extract will try Archive::Zip first and then fall back to the unzip binary if it fails. So it does seem that Archive::Zip is the preferred option.

Archive::Zip uses Compress::Raw::Zlib which is a low level interface to the zlib system library; so it's not a pure Perl implementation meaning it's going to be similar in performance to unzip. So, in other words, from a performance perspective there's no reason to pick unzip ahead of Archive::Zip.

like image 154
Dave Webb Avatar answered Sep 21 '22 10:09

Dave Webb