Skip to content

Instantly share code, notes, and snippets.

@taglia
Created January 8, 2014 10:21
Show Gist options
  • Save taglia/8314652 to your computer and use it in GitHub Desktop.
Save taglia/8314652 to your computer and use it in GitHub Desktop.
Compute SHA1 hash of the file given as first argument. Reads big files in chunks to avoid using all the available memory.
require 'openssl'
file_name = ARGV.first
digest = OpenSSL::Digest::SHA1.new
file = File.open(file_name, "rb")
until file.eof?
print "#"
digest.update file.read(2**24)
end
file.close
print "\n"
print digest.hexdigest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment