Module: Mmi::InstallUtils

Defined in:
lib/mmi/install_utils.rb

Class Method Summary collapse

Class Method Details

.download_to_file(url, target_file, content_hash = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mmi/install_utils.rb', line 11

def download_to_file(url, target_file, content_hash=nil)
	raise 'content_hash must be nil or an instance of Mmi::ContentHash::Base' unless content_hash.nil? || content_hash.is_a?(Mmi::ContentHash::Base)
	
	FileUtils.mkdir_p(File.dirname(target_file))
	
	stream = URI.parse(url).open
	
	IO.copy_stream(stream, target_file)
	
	raise "Failed to match #{target_file} with #{content_hash.inspect}!" if content_hash && !content_hash.match_file?(target_file)
end