Created
May 17, 2013 00:33
-
-
Save azenla/5596183 to your computer and use it in GitHub Desktop.
Groovy Script to calculate SHA1 Sums for HUGE files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.MessageDigest | |
int KB = 1024 | |
int MB = 1024*KB | |
File f = new File(args[0]) | |
if (!f.exists() || !f.isFile()) { | |
println "Invalid file $f provided" | |
println "Usage: groovy sha1.groovy <file_to_hash>" | |
} | |
def messageDigest = MessageDigest.getInstance("SHA1") | |
long start = System.currentTimeMillis() | |
f.eachByte(MB) { byte[] buf, int bytesRead -> | |
messageDigest.update(buf, 0, bytesRead); | |
} | |
def sha1Hex = new BigInteger(1, messageDigest.digest()).toString(16).padLeft( 40, '0' ) | |
long delta = System.currentTimeMillis()-start | |
println "$sha1Hex took $delta ms to calculate" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment