in reply to unable to extract same file twice using Archive::Zip

This sounds like another xy...
I got lost halfway through the first paragraph. What is the bigger picture for what you are trying to achieve?

I have to extract a zip file exactly in the order the files are present in the zip

why do you think that? At face value, thats simply not true. Whats the real reason why you (think you) need to process them that way?

Also, perhaps you can show us a short example of your code that has this problem, to try and make things clearer?
  • Comment on Re: unable to extract same file twice using Archive::Zip

Replies are listed 'Best First'.
Re^2: unable to extract same file twice using Archive::Zip
by Pickwick (Beadle) on Jul 06, 2010 at 09:44 UTC
    why do you think that? At face value, thats simply not true. Whats the real reason why you (think you) need to process them that way?
    I really have to, because I have a server which processes the zip files, does some checking and writes a protocol. Another client gets that protocol and does some checking on the zip contents itself with the infos from the servers protocol. Server and client assume the order of the zip contents as processing order of the protocol. That's nothing to change now.
    Also, perhaps you can show us a short example of your code that has this problem, to try and make things clearer?

    I don't think my code will help you, therefore I wrote a more simple example.

    my $zip = Archive::Zip->new(); $zip->read('someFile.zip'); foreach my $member ($zip->members()) { $member->extractToFileNames('foo.txt'); $member->extractToFileNames('bar.txt'); }

    The second try to extract the same member seems always to fail and I can't find an example which states that it is general possible to extract the same member more than once or not.

      Using your example it would make more sense to simply copy foo.txt as bar.txt instead of extracting it twice...


      So the issues/requirements you are facing at this point are:
      • I have to extract a zip file exactly in the order the files are present in the zip

      • I must extract the file from the archive twice as i cannot copy the extracted version to the second location

      Forgive me, but I don't understand. I would gladly offer whatever help I can provide, but this problem your facing doesn't make sense... please clarify

      PS.
      It's really a lot easier, and the files need to be extracted twice are really small, to extract some members twice, rather than storing which member already has been extracted and reuse those files and cleaning up later etc. .
      For what its worth, how about this approach:
      1. Obtain your "special" ordering of your zip file members.  my @member_order = $zip->members();
      2. Extract the entire archive to a directory. $zip->extractTree( 'stuff', '/tmp' );
      3. Process/reprocess the files in the extracted temp directory as required, based on their order within @member_order

      If this approach is unsuitable, why not?
        I must extract the file from the archive twice as i cannot copy the extracted version to the second location

        Of course I can. Ihe problem is that I don't wanted to always remember what already has been extracted, let it stay on the disk, reuse it, if even necessary, and cleanup later. Extracting it a second time if I already know that it's needed and don't have to look if it's already extracted would have been less code.

        Forgive me, but I don't understand. I would gladly offer whatever help I can provide, but this problem your facing doesn't make sense... please clarify

        The main question is: Is there a limitation on how often one can extract the same zip member and if, why? I don't see any reason why one shouldn't be able to extract a member more than once, if he wants to.

        If this approach is unsuitable, why not?

        In my mind it's waste of space to extract everything at once if I always just need one or two files from the archive. If there are two same named files in the archive you get a problem, too.

        But as I said before, I really would like to know if it's possible to extract a member more than once or not. Maybe I'm just missing something like endRead in the proper way or stuff like that.