File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11require "digest"
22require "fileutils"
3- require "net/http "
3+ require "open-uri "
44require "tmpdir"
55
66version = "9.15.6755"
7272
7373$stdout. sync = true
7474
75- def download_file ( url , download_path , redirects = 0 )
76- raise "Too many redirects" if redirects > 10
77-
78- uri = URI ( url )
79- location = nil
80-
81- Net ::HTTP . start ( uri . host , uri . port , use_ssl : true ) do |http |
82- request = Net ::HTTP ::Get . new ( uri )
83- http . request ( request ) do |response |
84- case response
85- when Net ::HTTPRedirection
86- location = response [ "location" ]
87- when Net ::HTTPSuccess
88- i = 0
89- File . open ( download_path , "wb" ) do |f |
90- response . read_body do |chunk |
91- f . write ( chunk )
92-
93- # print progress
94- putc "." if i % 50 == 0
95- i += 1
96- end
97- end
98- puts # newline
99- else
100- raise "Bad response"
101- end
102- end
103- end
104-
105- # outside of Net::HTTP block to close previous connection
106- download_file ( location , download_path , redirects + 1 ) if location
107- end
108-
10975# download
11076download_path = "#{ Dir . tmpdir } /#{ filename } "
11177unless File . exist? ( download_path )
11278 puts "Downloading #{ url } ..."
113- download_file ( url , download_path )
79+ IO . copy_stream ( URI . parse ( url ) . open ( max_redirects : 10 ) , download_path )
11480end
11581
11682# check integrity - do this regardless of if just downloaded
You can’t perform that action at this time.
0 commit comments