Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Archive::Zip
msr
Hi,
I've a requirement on Archiving. Basically requirement is, there are four zip files at different paths. Need to create a consolidated zip by extracting the content from four zip files .
Sample source structure
source_folder/test1.zip
source_folder/sub_src_folder1/test2.zip
source_folder111/sub_src_folder1/sub_src_folder2/test3.zip
source_folder222/sub_src_folder1/sub_src_folder2/test4.zip
Sample target zip should contain below structure:
/target_folder/folder11/folder12/zip1content
/target_folder/folder11/folder13/zip2content
/target_folder/folder11/folder14/zip3content
/target_folder/folder11/folder15/zip4content
Finally we need to prepare zip for 'target_folder'. The above target folders are temporary. Once the target zip creation completed then we can delete target_folder.
As the requirement is related to zip, I thought of using Archive::Zip.
Is it possible to create final zip without creating intermediate temporary folder structure(target_folder) by using in-memory concept?
Please suggest feasible design for my requirement.
Env:
perl 5, version 14, subversion 2 (v5.14.2)
Unix
Thanks in advance,
MSR
Find more posts tagged with
Comments
nipper
addFile can take two parameters, the path (to the "docroot") and then to the file:
$zip->addFile($filepath, "template/".$shortfile);
You would need to have the 2nd parameter match the output you want. If you can do that, you are golden
Rick Poulin
Please suggest feasible design for my requirement.
Seems like you've already got the design figured out. The only piece you're missing is straight out of the perldoc for Archive::Zip
[PHP]
addMember( $member )
Append a member (possibly from another zip file) to the zip file. Returns the new member. Generally, you will use addFile(), addDirectory(), addFileOrDirectory(), addString(), or read() to add members.
# Move member named 'abc' to another zip:
my $member = $sourceZip->removeMember( 'abc' );
$targetZip->addMember( $member );
[/PHP]
The only consideration about doing all this in memory is you should make sure your zip file isn't going to be very large.
msr
Thanks for your suggestion.
I've one more constraint. I want to move the all the content from src zip to target zip at a time instead on iteration to save time.
I found some thing as below
# add all readable files and directories below . as xyz/*
$zip->addTree( '.', 'xyz' );
# add all .c files below /tmp as stuff/*
$zip->addTreeMatching( '/tmp', 'stuff', '\.c$' );
But the source should be a folder. It should not be a zip.
Please suggest any hint on this approach.
Thanks,
MSR.
Rick Poulin
Between this and
your other thread
, I'm inclined to respond RTFM. You're not asking for design help, you're asking for what the API offers and how to use it.
BIRT_web20_details_mod3.rptdesign
msr
Hi,
I dont want to confuse you with multiple requests in the same thread. Thats why i have created separate thread with different approach. Apologies for creation of two threads. For your second question, I understand your design. But while implementing, I got an idea of why cant we do in bulk copy instead of loop. Appreciate your comment on my idea.
Thanks,
Msr