mhd.tahawi has asked for the wisdom of the Perl Monks concerning the following question:

I am changing a PERL code that does compression to be able to handle the zip64 extension.
the old code is using Archive::Zip module that can be used as follows.
# Create a Zip file use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); # Add a file from disk my $file_member = $zip->addFile( 'xyz.pl', 'AnotherName.pl' );
Archive::Zip doesn't support zip64 extension and because of that I am using IO::Compress::Zip module instead.
I am looking for a way to mimic the `addfFile` functionality some way or another, renaming while zipping or maybe editing the archives after zipping.
I can't find any PERL module that can help me in doing so.
  1. Is there any way in PERL to do that ?
  2. In case there is not a direct way, can I change something in the header of the archive file to rename its members ?
Thank you

Replies are listed 'Best First'.
Re: Renaming a file member in zip64 archive
by AppleFritter (Vicar) on Aug 06, 2014 at 17:11 UTC

    I don't think IO::Compress::Zip can do that, given that the module's documentation specifically says this:

    The primary purpose of this module is to provide streaming write access to zip files and buffers. It is not a general-purpose file archiver.

    Archive::Zip::SimpleZip appears to support the zip64 extension, have you looked into that?

    There's also a bug for adding zip64 support to Archive::Zip. It's existed for several years, so my gut feeling is that the author's not gonna fix it anytime soon, but patches are presumably welcome.

      Archive::Zip::SimpleZip is just a wrapper around IO::Compress::Zip. It cannot modify existing zip files. I have no plans to change either modules to allow updating of existing Zip archives.

      Regarding renaming of zip file members for Zip64 archives, I'm not aware of anything that supports doing it in pure Perl. Only thing I can suggest is How can I rename zipfile members without extracting and recompressing them?

Re: Renaming a file member in zip64 archive
by pmqs (Friar) on Aug 06, 2014 at 21:42 UTC

    Misread your question. Thought you needed to rename after the zip file was created. That was the requirement when you asked a very similar question in this message: Archive::Zip error when reading a zip file format error: bad signature. I assume your requirements have changed?

    Try this - it will automatically create the output file as a Zip64 compliant Zip archive if required (i.e. if the size exceed 4 Gig or you have > 64 members in the zip archive). Otherwise it creates a standard Zip archive.

    use Archive::Zip::SimpleZip qw($SimpleZipError) ; my $z = new Archive::Zip::SimpleZip "my1.zip" or die "Cannot create zip file: $SimpleZipError\n" ; $z->add('xyz.pl', Name => 'AnotherName.pl' ); $z->close();

    If you want to force the creation of a Zip64 archive (even when the archive is small enough not to need it) add the Zip64 option when creating the Archive::Zip::SimpleZip object, like this

    my $z = new Archive::Zip::SimpleZip "my1.zip", Zip64 => 1 or die "Cannot create zip file: $SimpleZipError\n" ;
      That should of course say

      "... if the size exceed 4 Gig or you have > 64k members in the zip archive..."