Skip to content

Instantly share code, notes, and snippets.

@mattgaidica
Created June 7, 2012 04:45
Show Gist options
  • Save mattgaidica/2886623 to your computer and use it in GitHub Desktop.
Save mattgaidica/2886623 to your computer and use it in GitHub Desktop.
Create an MD5 hash (checksum) for an external file
require 'tempfile'
require 'net/http'
require 'digest/md5'
file = Tempfile.new('temp_file')
begin
Net::HTTP.start("domain.tld") { |http|
resp = http.get("/02185773dcb5a468df6b.pdf")
file.write(resp.body)
}
hash = Digest::MD5.hexdigest(File.read(file))
puts hash
ensure
file.close
file.unlink
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment