Calculating a SHA1 hash for large files Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Description

There are a number of posts on the net about SHA1 hashing in groovy but they tend to assume small data sets. This script calculates a SHA1 hash for an arbitrary size argument file using a one MB memory buffer.

Note that the script uses the File.eachByte(int, closure) method which is only available in Groovy v1.7.4 and later. You can naturally replace this construct with some other pattern, but as it fits so beautifully for the purpose, the script makes use of it.

Code

Paste the below into a file "sha1.groovy" and run with a file param, i.e.:

Calling the script

and now for the code:

Script Code

Author: Matias Bjarland, Iteego Inc

 

Search

Results of your search request can come from various sources: the Groovy website itself, the JIRA issues, the API documentation, as well as a few other interesting Groovy-related blogs.

  By  -  pages  -  views  - last modified