Class: Rpremote::NukeFirmware

Inherits:
Object
  • Object
show all
Defined in:
lib/rpremote/nuke_firmware.rb,
sig/rpremote.rbs

Defined Under Namespace

Classes: DownloadError

Constant Summary collapse

URL =

Returns:

  • (String)
"https://github.com/raspberrypi/pico-sdk-prebuilts/releases/latest/download/nuke_universal.uf2"
FILENAME =

Returns:

  • (String)
"nuke_universal.uf2"
MAX_REDIRECTS =

Returns:

  • (Integer)
5

Instance Method Summary collapse

Constructor Details

#initialize(directory: Target::DEFAULT_CACHE_DIR, fetcher: nil) ⇒ NukeFirmware

Returns a new instance of NukeFirmware.

Parameters:

  • directory: (String) (defaults to: Target::DEFAULT_CACHE_DIR)
  • fetcher: (Object) (defaults to: nil)


16
17
18
19
# File 'lib/rpremote/nuke_firmware.rb', line 16

def initialize(directory: Target::DEFAULT_CACHE_DIR, fetcher: nil)
  @directory = File.expand_path(directory)
  @fetcher = fetcher || method(:download)
end

Instance Method Details

#setup(force: false) ⇒ String

Parameters:

  • force: (Boolean) (defaults to: false)

Returns:

  • (String)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rpremote/nuke_firmware.rb', line 21

def setup(force: false)
  FileUtils.mkdir_p(directory)
  return path if File.size?(path) && !force

  temporary = "#{path}.part"
  File.binwrite(temporary, fetcher.call(URL))
  raise DownloadError, "downloaded nuke_universal.uf2 is empty" unless File.size?(temporary)

  File.rename(temporary, path)
  path
rescue SystemCallError => e
  raise DownloadError, "cannot store nuke_universal.uf2: #{e.message}"
ensure
  FileUtils.rm_f(temporary) if temporary
end