Moha the almighty camel
Moha the almighty camel

Reputation: 4453

PERL - renaming a file member in zip64 archive

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

Upvotes: 0

Views: 556

Answers (2)

pmqs
pmqs

Reputation: 3705

I assume this is the same question you asked over on PerlMonks Renaming a file member in zip64 archive?

If so, here is the same reply.

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 > 64k 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" ;

Upvotes: 2

Andrey
Andrey

Reputation: 1818

I am not sure if there is a way to do it with IO::Compress::Zip, but. Why do not you rename files before adding them to archive? If you need to preserve original files with its names, copy the files to some temp folder, rename, and to archive and delete from temp after.

Upvotes: 0

Related Questions