Created
June 7, 2012 04:45
-
-
Save mattgaidica/2886623 to your computer and use it in GitHub Desktop.
Create an MD5 hash (checksum) for an external file
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 '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