Can I list contents of nested zipfile using Archive::Zip withoutextracting the outermost zip?

G

Graham Wood

I need to check the structure of a nested zipfile and I'm wondering if
it is possible to do this using Archive::Zip without having to extract
the contents of the outermost zipfile into a temporary directory.

The structure of the zipfile is:

1233456.zip
123456_ar.zip
123456/abcdef/xy/help/US/file1.htm
123456/abcdef/xy/help/US/file2.htm
123456/abcdef/xy/help/US/file3.htm
123456_bg.zip
123456_ce.zip


I want to do this:
1 open the 123456.zip
read the filename.zip list (I've got this far!)
foreach filename.zip (eg 123456_ar.zip)
list the contents of the filename.zip
}
}

Can I get there without extracting 1233456.zip first?

Thanks in advance

Graham
 
A

A. Sinan Unur

I want to do this:
1 open the 123456.zip
read the filename.zip list (I've got this far!)
foreach filename.zip (eg 123456_ar.zip)
list the contents of the filename.zip
}
}

Can I get there without extracting 1233456.zip first?

Have you looked at the docs?

http://search.cpan.org/~nedkonz/Archive-Zip-
1.09/lib/Archive/Zip.pod#Zip_Archive_Accessors

(URL wrapped in newsreader)

#! perl

use strict;
use warnings;

use Archive::ZIP qw( :ERROR_CODES :CONSTANTS );

my $zip = Archive::Zip->new('test.zip');

print map { "$_\n" } $zip->memberNames();

__END__
 
G

Graham Wood

A. Sinan Unur said:
[email protected]:




Have you looked at the docs?

http://search.cpan.org/~nedkonz/Archive-Zip-
1.09/lib/Archive/Zip.pod#Zip_Archive_Accessors
Yes, that's how I "got this far" already.
(URL wrapped in newsreader)

#! perl

use strict;
use warnings;

use Archive::ZIP qw( :ERROR_CODES :CONSTANTS );

my $zip = Archive::Zip->new('test.zip');

print map { "$_\n" } $zip->memberNames();

This will list the members in the first zipfile. However, all the
members of the first zipfile are themselves zipfiles as well. I'm
trying to find out how to call $zip->memberNames() on each member inside
the first zipfile.

I could just extract the first zipfile, then open each individual zip
that came out of it but I was hoping there was some way of doing the
whole thing in memory.

Graham
 
A

A. Sinan Unur

....
Yes, that's how I "got this far" already.

Fair enough. Sorry I misunderstood your question.

I am not familiar with the Archive::Zip module, but the following script
I cobbled together based on one of the examples seems to work. At first I
thought Archive::Zip::MemberRead would do the job but I ran into some
difficulties.

Here are the contents of the two zip files I used:

C:\Home> unzip -l test1.zip
Archive: test1.zip
Length Date Time Name
-------- ---- ---- ----
2040 01-10-04 20:13 test.zip
-------- -------
2040 1 file

C:\Home> unzip -l test.zip
Archive: test.zip
Length Date Time Name
-------- ---- ---- ----
398 12-04-03 23:13 dload/misc/ddd.pl
793 11-08-03 10:30 dload/misc/g.pl
1460 07-23-03 10:47 dload/misc/r.pl
940 07-23-03 23:40 dload/misc/s.pl
-------- -------
3591 4 files

Here is the script (no error checking):

C:\Home> cat t.pl
#! perl

use strict;
use warnings;

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use IO::Scalar;

my $zip = Archive::Zip->new('test1.zip');
my $member = $zip->memberNamed('test.zip');
my $member_contents = $member->contents();
my $member_contents_sh = IO::Scalar->new(\$member_contents);
my $member_zip = Archive::Zip->new();
$member_zip->readFromFileHandle($member_contents_sh);
print map { "$_\n" } $member_zip->memberNames();

__END__

C:\Home> t.pl
dload/misc/ddd.pl
dload/misc/g.pl
dload/misc/r.pl
dload/misc/s.pl

HTH.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top