#!/usr/bin/perl -- use strict; use warnings; use autodie qw/ chdir /; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use Data::Dump qw/ dd /;; use Path::Tiny qw/ path /; my $thisdir = shift || path( __FILE__ )->parent; chdir $thisdir; #~ my $fyle = "".path( $thisdir, 'goner-goner-gone.zip' ); my $fyle = 'goner-goner-gone.zip'; FillZip( $fyle ); StatZip( $fyle ); TrimZip( $fyle ); StatZip( $fyle ); path( $fyle )->remove; exit( 0 ); sub FillZip { my $outzip = shift; my $status; my $zip = Archive::Zip->new(); $zip->addString('hi'x33, 'hi.txt'); $zip->addString('hi'x33, 'ne/hi.txt'); $zip->addString('hi'x33, 'wo/hi.txt'); $zip->addString('hi'x33, 'one/hi.txt'); $zip->addString('hi'x33, 'two/hi.txt'); $zip->addDirectory('one/'); $zip->addDirectory('two/'); print "Trying to ->writeToFileNamed( $outzip )\n"; $status = $zip->writeToFileNamed( "$outzip" ); die "ERROR ->writeToFileNamed( $outzip ) , status == $status " if $status != AZ_OK; } sub TrimZip { my $outzip = shift; my $status; my $zip = Archive::Zip->new(); print "Trying to ->read( $outzip )\n"; $status = $zip->read( "$outzip" ); die "ERROR ->read( $outzip ) , status == $status " if $status != AZ_OK; for my $goner ( qw{ one/ one/hi.txt } ){ $zip->removeMember( $goner ) or print "whoops removeMember( $goner )\n"; } print "Trying to ->overwrite( $outzip )\n"; $status = $zip->overwrite( "$outzip" ); die "ERROR ->overwrite( $outzip ) , status == $status " if $status != AZ_OK; } sub StatZip { my( $file ) = @_; my $zip = Archive::Zip->new( $file ); print "\n## $file\n"; print $_->fileName, " \t\t\t $_\n" for $zip->membersMatching( '.*' ) ; #~ for $zip->membersMatching( '.*\..*' ) ; print "\n"; } __END__ Trying to ->writeToFileNamed( goner-goner-gone.zip ) ## goner-goner-gone.zip hi.txt Archive::Zip::ZipFileMember=HASH(0x103074c) ne/hi.txt Archive::Zip::ZipFileMember=HASH(0xb3d1d4) wo/hi.txt Archive::Zip::ZipFileMember=HASH(0x1030a2c) one/hi.txt Archive::Zip::ZipFileMember=HASH(0x1030c5c) two/hi.txt Archive::Zip::ZipFileMember=HASH(0x1030cec) one/ Archive::Zip::DirectoryMember=HASH(0x1030ecc) two/ Archive::Zip::DirectoryMember=HASH(0x103040c) Trying to ->read( goner-goner-gone.zip ) Trying to ->overwrite( goner-goner-gone.zip ) ## goner-goner-gone.zip hi.txt Archive::Zip::ZipFileMember=HASH(0x103070c) ne/hi.txt Archive::Zip::ZipFileMember=HASH(0x1030e2c) wo/hi.txt Archive::Zip::ZipFileMember=HASH(0x103420c) two/hi.txt Archive::Zip::ZipFileMember=HASH(0x103395c) two/ Archive::Zip::DirectoryMember=HASH(0x1030ccc)