#!/usr/bin/perl use strict; use IO::File; use Archive::Zip qw/:ERROR_CODES :CONSTANTS/; my $Usage = "Usage: $0 file.zip\n"; die $Usage unless ( @ARGV == 1 and -f $ARGV[0] ); my $zip = Archive::Zip->new(); if ( $zip->read( $ARGV[0] ) != AZ_OK ) { die "Archive::Zip failed to read $ARGV[0]\n"; } for my $zfile ( $zip->members ) { my $fh = IO::File->new_tmpfile or die "Unable to create temp file: $!\n"; $fh->binmode; if ( $zfile->extractToFileHandle( $fh ) != AZ_OK ) { warn sprintf( "Extraction failed for %s\n", $zfile->fileName() ); next; } seek( $fh, 0, 0 ); my ( $buffer, $nread ); my $crc = 0; while ( $nread = $fh->read( $buffer, 32768 )) { $crc = Archive::Zip::computeCRC32( $buffer, $crc ); } my $status = ( $crc == $zfile->crc32()) ? "good" : "broke"; printf( "Status: %s\tcomp crc: %08x\tfile crc: %08x\t%s\n", $status, $crc, $zfile->crc32(), $zfile->fileName()); } #### $member->extractToFileHandle($fh); if ($member->extractToFileHandle($fh) != 0){ print "Error in $archivedir$filename\n"; next; }