Recursive descent in zip files?

雨燕双飞 提交于 2019-12-12 02:29:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9330602/recursive-descent-in-zip-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!