I tried it like this, and on the first zip file I happened to look at, it worked just fine -- the computed crcs all matched the ones stated in the zip file itself:
#!/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()); }

UPDATE: I wonder if the problem in the OP code might be here:

$member->extractToFileHandle($fh); if ($member->extractToFileHandle($fh) != 0){ print "Error in $archivedir$filename\n"; next; }
It looks like you are extracting the file twice to the same file handle, and maybe that is causing each file to have its contents doubled (and you would almost never get the same crc in that case). In fact, I just added a second "extractToFileHandle" call in my version, and all the data files failed the crc check.

In reply to Re: Zip file CRC validation by graff
in thread Zip file CRC validation by msalerno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.