Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Archive::Zip for unzipping to directory?

by Anonymous Monk
on Apr 14, 2008 at 00:28 UTC ( [id://680180]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Can Archive::Zip be used for the equivalent of
unzip archive.zip -d target/directory?
If so: How? If not: What's the best alternative?
(PHM)

Replies are listed 'Best First'.
Re: Archive::Zip for unzipping to directory?
by Khen1950fx (Canon) on Apr 14, 2008 at 01:07 UTC
    A quick google turned up Archive::Unzip::Burst.

    #!/usr/bin/perl use strict; use warnings; use Archive::Unzip::Burst 'unzip'; unzip("zipfile.zip", "targetdirectory");

      I have to mark this with a big "Whoa there!"

      I wrote Archive::Unzip::Burst because Archive::Zip was notoriously slow when starting a PAR packaged application. A::U::B is just a very, very thin wrapper around a copy of the infozip library and exposes only a tiny fraction of the features.

      More problematic yet, the module is known to only build on Linux. There was some effort by people on the PAR mailing list to get it to work on Win32, but to no avail yet.

      Note that infozip itself is portable, just the integration into the module build system was... challenging.

      By the way: Patches welcome :)

      Cheers,
      Steffen

Re: Archive::Zip for unzipping to directory?
by poolpi (Hermit) on Apr 14, 2008 at 09:06 UTC

    See extractTree from Archive::Zip

    #!/usr/bin/perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); unless ( $zip->read( 'files.txt.zip' ) == AZ_OK ) { die 'read error'; } # (Linux) root dest $zip->extractTree( '', 'tmp/' );

    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
Re: Archive::Zip for unzipping to directory?
by ferreira (Chaplain) on Apr 14, 2008 at 12:47 UTC

    As yet another alternative: Archive::Extract can do it in a very straightforward manner:

    use Archive::Extract; my $x = Archive::Extract->new( archive => ’archive.zip’ ); $x->extract( to => 'target/directory' ) or die $x->error;

    It (Archive::Extract) has the bonus benefit of working for .tar.gz, .tar.bz2 and other archive types as well. In turn, it has some drawbacks in the current implementation that take the entire contents of the archive into memory (due to Archive::Tar and Compress::unLZMA, but that does not affect handling zip files, which can use Archive::Zip or the utility unzip under the hood.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://680180]
Approved by Sinistral
Front-paged by Sinistral
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-16 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found