Class: Rpremote::NukeFirmware
- Inherits:
-
Object
- Object
- Rpremote::NukeFirmware
- Defined in:
- lib/rpremote/nuke_firmware.rb,
sig/rpremote.rbs
Defined Under Namespace
Classes: DownloadError
Constant Summary collapse
- URL =
"https://github.com/raspberrypi/pico-sdk-prebuilts/releases/latest/download/nuke_universal.uf2"- FILENAME =
"nuke_universal.uf2"- MAX_REDIRECTS =
5
Instance Method Summary collapse
-
#initialize(directory: Target::DEFAULT_CACHE_DIR, fetcher: nil) ⇒ NukeFirmware
constructor
A new instance of NukeFirmware.
- #setup(force: false) ⇒ String
Constructor Details
#initialize(directory: Target::DEFAULT_CACHE_DIR, fetcher: nil) ⇒ NukeFirmware
Returns a new instance of NukeFirmware.
16 17 18 19 |
# File 'lib/rpremote/nuke_firmware.rb', line 16 def initialize(directory: Target::DEFAULT_CACHE_DIR, fetcher: nil) @directory = File.(directory) @fetcher = fetcher || method(:download) end |
Instance Method Details
#setup(force: false) ⇒ 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.}" ensure FileUtils.rm_f(temporary) if temporary end |