1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/downloader.rb
hsbt 204a83f5f3 * tool/downloader.rb: make Downloader class to general download utility.
It can be used without config.guess and configu.sub.
* tool/get-config_files: ditto.
* tool/make-snapshot: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-24 01:26:21 +00:00

11 lines
281 B
Ruby

require 'open-uri'
class Downloader
def self.download(url, name, dir = nil)
data = URI(url).read
file = dir ? File.join(dir, name) : name
open(file, "wb", 0755) {|f| f.write(data)}
rescue => e
raise "failed to download #{name}\n#{e.message}: #{uri}"
end
end