Sha256: a1b5299c41949c1155f783965a46ebb83cc90a8d19032795e306805854e2c20b

Contents?: true

Size: 897 Bytes

Versions: 6

Compression:

Stored size: 897 Bytes

Contents

require 'typhoeus'
Shoes.app do
  button "typheous" do
    st_time = Time.now
    filesz = 0
    downloaded_file = File.open 'huge.iso', 'wb'
    @th = Thread.new do
      request = Typhoeus::Request.new("http://walkabout.mvmanila.com/public/share/Ytm-2.exe")
      request.on_headers do |response|
        if response.code != 200
          raise "Request failed"
        end
        puts "length #{response.headers['Content-Length']}"
        filesz = response.headers['Content-Length'].to_i
      end
      request.on_body do |chunk|
        $stdout.puts "."
        downloaded_file.write(chunk)
      end
      request.on_complete do |response|
        downloaded_file.close
        end_time = Time.now
        elapsed = end_time.to_i - st_time.to_i
        $stderr.puts "Finished in #{elapsed} secs #{(filesz/1024)/elapsed} KB/s"
        @th.join
      end
      request.run
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
scarpe-0.4.0 examples/legacy/not_checked/shoes3-tests/curl/typ.rb
scarpe-0.3.0 examples/legacy/not_checked/shoes3-tests/curl/typ.rb
scarpe-0.2.2 examples/legacy/not_checked/shoes3-tests/curl/typ.rb
lacci-0.2.1 examples/legacy/not_checked/shoes3-tests/curl/typ.rb
scarpe-0.2.1 examples/legacy/not_checked/shoes3-tests/curl/typ.rb
scarpe-0.2.0 examples/legacy/not_checked/shoes3-tests/curl/typ.rb