Class: RubyWasm::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_wasm/build/downloader.rb,
sig/ruby_wasm/build.rbs

Instance Method Summary collapse

Instance Method Details

#download(url, dest, message) ⇒ void

This method returns an undefined value.

Parameters:

  • url (String)
  • dest (String)
  • message (String)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ruby_wasm/build/downloader.rb', line 3

def download(url, dest, message)
  require "open-uri"
  content_length = 0
  uri = URI.parse(url)
  OpenURI.open_uri(
    uri,
    content_length_proc: ->(len) { content_length = len },
    progress_proc: ->(size) do
      print "\r#{message} (#{SizeFormatter.format(content_length)}) %.2f%%" %
              (size.to_f / content_length * 100)
    end
  ) { |f| File.open(dest, "wb") { |out| out.write f.read } }
  puts "\r"
end

#format_sizeString

Parameters:

  • size (Integer)

Returns:

  • (String)


338
# File 'sig/ruby_wasm/build.rbs', line 338

def format_size: (Integer size) -> String

#headBoolean

Parameters:

  • url (String)

Returns:

  • (Boolean)


341
# File 'sig/ruby_wasm/build.rbs', line 341

def head: (String url) -> bool