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

Discussion in 'Perl Misc' started by Graham Wood, Jan 9, 2004.

  1. Graham Wood

    Graham Wood Guest

    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
    Graham Wood, Jan 9, 2004
    #1
    1. Advertising

  2. Re: Can I list contents of nested zipfile using Archive::Zip without extracting the outermost zip?

    Graham Wood <> wrote in news:LUBLb.4
    $:

    > 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__



    --
    A. Sinan Unur
    (reverse each component for email address)
    A. Sinan Unur, Jan 9, 2004
    #2
    1. Advertising

  3. Graham Wood

    Graham Wood Guest

    A. Sinan Unur wrote:
    > Graham Wood <> wrote in news:LUBLb.4
    > $:
    >
    >
    >>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
    >

    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
    Graham Wood, Jan 10, 2004
    #3
  4. Re: Can I list contents of nested zipfile using Archive::Zip without extracting the outermost zip?

    Graham Wood <> wrote in news:3FFFF821.8020606
    @oracle.com:

    > A. Sinan Unur wrote:
    >> Graham Wood <> wrote in news:LUBLb.4
    >> $:
    >>
    >>
    >>>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?

    ....
    > 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.

    --
    A. Sinan Unur
    (reverse each component for email address)
    A. Sinan Unur, Jan 11, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Trahan
    Replies:
    10
    Views:
    196
  2. Twig
    Replies:
    1
    Views:
    127
    A. Sinan Unur
    Jan 27, 2006
  3. MoshiachNow
    Replies:
    2
    Views:
    272
    Ilya Zakharevich
    Oct 4, 2006
  4. MoshiachNow

    Archive::Zip - zip file has "invalid" format

    MoshiachNow, Oct 5, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    166
  5. Bo Yang
    Replies:
    9
    Views:
    299
    -berlin.de
    Nov 20, 2006
Loading...

Share This Page