Skip to content

Instantly share code, notes, and snippets.

@julik
Created December 9, 2013 11:08
Show Gist options
  • Save julik/7870653 to your computer and use it in GitHub Desktop.
Save julik/7870653 to your computer and use it in GitHub Desktop.
digest a file with Ruby via OpenSSL
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