1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/examples/stream_download.rb

25 lines
575 B
Ruby
Raw Normal View History

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'
class StreamDownload
include HTTParty
base_uri 'https://cdn.kernel.org/pub/linux/kernel/v4.x'
end
# download file linux-4.6.4.tar.xz without using the memory
response = nil
filename = 'linux-4.6.4.tar.xz'
File.open(filename, 'w') do |file|
response = StreamDownload.get('/linux-4.6.4.tar.xz', stream_body: true) do |fragment|
file.binmode
file.write(fragment)
end
end
pp "Success: #{response.success?}"
pp File.stat(filename).inspect