2016-07-12 15:19:49 -04:00
|
|
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require File.join(dir, 'httparty')
|
|
|
|
require 'pp'
|
|
|
|
|
|
|
|
# download file linux-4.6.4.tar.xz without using the memory
|
|
|
|
response = nil
|
2016-07-29 08:16:39 -04:00
|
|
|
filename = "linux-4.6.4.tar.xz"
|
|
|
|
url = "https://cdn.kernel.org/pub/linux/kernel/v4.x/#{filename}"
|
2016-07-12 15:19:49 -04:00
|
|
|
|
2016-07-29 08:16:39 -04:00
|
|
|
File.open(filename, "w") do |file|
|
|
|
|
response = HTTParty.get(url, stream_body: true) do |fragment|
|
2019-01-23 01:02:55 -05:00
|
|
|
if [301, 302].include?(fragment.code)
|
|
|
|
print "skip writing for redirect"
|
|
|
|
elsif fragment.code == 200
|
|
|
|
print "."
|
|
|
|
file.write(fragment)
|
|
|
|
else
|
|
|
|
raise StandardError, "Non-success status code while streaming #{fragment.code}"
|
|
|
|
end
|
2016-07-12 15:19:49 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-29 08:16:39 -04:00
|
|
|
puts
|
2016-07-12 15:19:49 -04:00
|
|
|
|
|
|
|
pp "Success: #{response.success?}"
|
|
|
|
pp File.stat(filename).inspect
|
2016-07-29 08:16:39 -04:00
|
|
|
File.unlink(filename)
|