in reply to Archive::Zip - what am I missing?

It works like this :

#!/usr/bin/perl -w use strict; use Archive::Zip qw(:ERROR_CODES); use Data::Dumper; my $z = Archive::Zip->new(); unless ( $z->read( 'img.zip' ) == AZ_OK ) { die 'read error'; } my $old = $z->removeMember( 'old.img' ); my $new = $z->replaceMember( $old, 'new.img' ); print Dumper $z->members();

hth,
PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Replies are listed 'Best First'.
Re^2: Archive::Zip - what am I missing?
by Anonymous Monk on Apr 10, 2008 at 10:46 UTC
    Try it, the file doesn't get replaced. You need my $newimage1 =  Archive::Zip::Member->newFromFile(
      Thanks for the help! I knew I had to be missing something... yes, that allows newimage1.jpeg to be included into the zip archive, however, it puts it in the central directory.
      #!/usr/bin/perl use strict; use Archive::Zip qw(:ERROR_CODES); my $zipFile = Archive::Zip->new(); my $status = $zipFile->read( '/home/clueless/blabla.zip' ); my $oldimage1 = 'branch/stick/image1.jpeg'; my $newimage1 = Archive::Zip::Member->newFromFile( 'newimage1.jpeg' ); my $oldmember = $zipFile->replaceMember( $oldimage1, $newimage1 ); my $stat = $zipFile->overwrite();
      I'm trying to replace image1.jpeg in the branch/stick archive directory.

      Maybe my thought process is incorrect but it would seem to me that a replaceMember method would put the new member in exactly the same location as the old one. It does not appear to be that way... must I declare the archive directory as well? How do I do so? I didn't find any specific methods which appeared to handle this... (of course, I could be overlooking something again.)

      regexes
        If you want if you want to make "newimage1.jpeg" become "branch/stick/image1.jpeg" within the archive, then do this:
        #!/usr/bin/perl use strict; use Archive::Zip qw(:ERROR_CODES); my $zipFile = Archive::Zip->new(); my $status = $zipFile->read( '/home/clueless/blabla.zip' ); my $oldimage1 = 'branch/stick/image1.jpeg'; my $newimage1 = 'newimage1.jpeg'; my $oldmember = $zipFile->updateMember( $oldimage1, $newimage1 ); my $stat = $zipFile->overwrite();
        If you want to remove "branch/stick/image1.jpeg" and add "newimage1.jpeg" under "branch/stick/" do this:
        #!/usr/bin/perl use strict; use Archive::Zip qw(:ERROR_CODES); my $zipFile = Archive::Zip->new(); my $status = $zipFile->read( '/home/clueless/blabla.zip' ); my $oldimage1 = 'branch/stick/image1.jpeg'; my $newimage1 = 'newimage1.jpeg'; my $oldmember = $zipFile->removeMember( $oldimage1 ); my $newmember = $zipFile->addFile( $newimage1, "branch/stick/$newimage +1"); my $stat = $zipFile->overwrite();