Created
November 27, 2012 20:15
-
-
Save mshock/4156726 to your computer and use it in GitHub Desktop.
Perl zip utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! perl -w | |
package ZipUtil; | |
use strict; | |
use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
use Exporter 'import'; | |
our @EXPORT = qw(unzip); | |
# for CLI | |
my ($zip_file, $out_file, $filter) = @ARGV; | |
unzip($zip_file, $out_file, $filter) if scalar @ARGV; | |
1; | |
# for importers | |
sub unzip { | |
my ($zip_file, $out_file, $filter) = @_; | |
my $zip = Archive::Zip->new($zip_file); | |
unless ($zip->extractTree($filter || '', $out_file) == AZ_OK) { | |
warn "unzip not successful: $!\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome. Waisted 2 hours trying different methods that work on older OSX (Snow Leopard) and it's default Perl for an installer I'm working on, and your code here was just the ticket to show me the fix. Why this isn't so well advertised and known for unzipping on Perl -- I'll never know.