Skip to content

Instantly share code, notes, and snippets.

@thisivan
Created August 23, 2010 23:54
Show Gist options
  • Save thisivan/546593 to your computer and use it in GitHub Desktop.
Save thisivan/546593 to your computer and use it in GitHub Desktop.
# Hex digest a file, without loading the whole file into memory:
require 'digest/md5'
def md5sum_file(path)
digest = Digest::MD5.new
File.open(path, 'r') do |file|
while buffer = file.read(1024*8)
digest << buffer
end
end
digest.hexdigest
end
puts md5sum_file('/etc/hosts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment