Created
December 9, 2013 11:08
-
-
Save julik/7870653 to your computer and use it in GitHub Desktop.
digest a file with Ruby via OpenSSL
This file contains hidden or 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' | |
def digest_file(file_path, digest_class) | |
chunk_size = 1024 * 1024 # a meg | |
d = digest_class.new | |
File.open(file_path, 'r') do | f | | |
while chunk = f.read(chunk_size) do | |
d << chunk | |
end | |
end | |
d.hexdigest | |
end | |
puts digest_file('/Volumes/FASZT/GiganticFie.huge', OpenSSL::Digest::SHA256) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment