Sha256: 42c8151fea44da84abc2fb3a3f3b38baeeaadbde8e2afc2097ec83da85ed5e2e

Contents?: true

Size: 755 Bytes

Versions: 137

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

137 entries across 111 versions & 7 rubygems

Version Path
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/stream_download.rb