Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

perl - Recursive descent in zip files?

I am trying to recursively scan a bunch of zip files and I am using, of course, archive::zip. I would like to avoid expanding the archive's content in a temporary folder. I would like to be able to use something like (nearly-pseudo code):

sub CALLMYSELFAGAIN .....

my @members = $currentZipFile->members();
while(my $member = pop @members){                       
    if ($member->isTextFile()){
        push @content, $member->contents();
    }elsif(isZipFile($member->fileName())){
        CALLMYSELFAGAIN($member);
    }

The problem is, $member->can("memberNames")) returns false, so $member is NOT an archive::zip in the sense that I could not open it again as a zip file. Or am I wrong?

Any hint?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do this:

elsif (isZipFile($member->filename)) {
    my $contents = $currentZipFile->contents($member);
    open my $fh, '<', $contents; # In-memory filehandle
    my $child_zip = Archive::Zip->new;
    $child_zip->readFromFileHandle($fh);
    CALLMYSELFAGAIN($child_zip);
}

but expect that to be very memory intensive, especially if you go more than one level deep.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...