Created
January 8, 2014 10:21
-
-
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.
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
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