Sha256: 42c8151fea44da84abc2fb3a3f3b38baeeaadbde8e2afc2097ec83da85ed5e2e

Contents?: true

Size: 755 Bytes

Versions: 135

Compression:

Stored size: 755 Bytes

Contents

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
filename = "linux-4.6.4.tar.xz"
url = "https://cdn.kernel.org/pub/linux/kernel/v4.x/#{filename}"

File.open(filename, "w") do |file|
  response = HTTParty.get(url, stream_body: true) do |fragment|
    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
  end
end
puts

pp "Success: #{response.success?}"
pp File.stat(filename).inspect
File.unlink(filename)

Version data entries

135 entries across 110 versions & 6 rubygems

Version Path
harbr-0.1.37 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
httparty-0.21.0 examples/stream_download.rb
httparty-0.20.0 examples/stream_download.rb
httparty-0.19.1 examples/stream_download.rb
httparty-0.19.0 examples/stream_download.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.9 vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.8 vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.7 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.7 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb
paynow_sdk-1.0.6 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/stream_download.rb