| 136 | end |
| 137 | |
| 138 | def download_server(uri, destination) |
| 139 | net_http_start('github-releases.githubusercontent.com') do |http| |
| 140 | request = Net::HTTP::Get.new uri |
| 141 | resp = http.request(request) do |response| |
| 142 | total = response.content_length |
| 143 | progress = 0 |
| 144 | segment_count = 0 |
| 145 | |
| 146 | response.read_body do |segment| |
| 147 | progress += segment.length |
| 148 | segment_count += 1 |
| 149 | |
| 150 | if (segment_count % 15).zero? |
| 151 | percent = progress.fdiv(total) * 100 |
| 152 | print "#{CL_RESET}Downloading #{destination.path}: #{percent.to_i}% (#{progress} / #{total})" |
| 153 | segment_count = 0 |
| 154 | end |
| 155 | |
| 156 | destination.write(segment) |
| 157 | end |
| 158 | end |
| 159 | |
| 160 | raise Error, "#{resp.code} for #{destination.path}" unless resp.is_a? Net::HTTPSuccess |
| 161 | end |
| 162 | end |
| 163 | end |
| 164 | |
| 165 | # |