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.2.0 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.90 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.88 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.87 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.86 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.85 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.84 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.83 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.82 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb