Skip to content

Instantly share code, notes, and snippets.

@archydragon
Created March 28, 2013 04:53
Show Gist options
  • Save archydragon/5260747 to your computer and use it in GitHub Desktop.
Save archydragon/5260747 to your computer and use it in GitHub Desktop.
useless CRC32 validator
#!/bin/bash
CRC32="/usr/bin/crc32"
FILENAME=$1
echo -ne "$FILENAME\t\t"
NAMED_CRC=`echo $FILENAME | sed -e 's/^.*\[\(.\{8\}\)\]\..*$/\1/g' | tr '[:upper:]' '[:lower:]'`
CALCULATED_CRC=`$CRC32 "$FILENAME" | tr '[:upper:]' '[:lower:]'`
if [[ $NAMED_CRC == $CALCULATED_CRC ]]; then
echo -e "OK"
else
echo -e "fail!"
fi
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
# Computes and prints to stdout the CRC-32 values of the given files
use strict;
use lib qw( blib/lib lib );
use Archive::Zip;
use FileHandle;
my $totalFiles = scalar(@ARGV);
foreach my $file (@ARGV) {
if ( -d $file ) {
warn "$0: ${file}: Is a directory\n";
next;
}
my $fh = FileHandle->new();
if ( !$fh->open( $file, 'r' ) ) {
warn "$0: $!\n";
next;
}
binmode($fh);
my $buffer;
my $bytesRead;
my $crc = 0;
while ( $bytesRead = $fh->read( $buffer, 32768 ) ) {
$crc = Archive::Zip::computeCRC32( $buffer, $crc );
}
printf( "%08x", $crc );
print("\t$file") if ( $totalFiles > 1 );
print("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment