Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 later versions of groovy (I know for a fact that it is not available in 1.7.3 and is available in 1.7.6). 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.:

...