Class: NativeFile

Inherits:
Object
  • Object
show all
Defined in:
ext/asherah/native_file.rb

Overview

Downloads native file and verifies checksum

Constant Summary collapse

LIB_NAME =
'libasherah'
ROOT_DIR =
File.expand_path('../../', __dir__)
CHECKSUMS_FILE =
File.expand_path('checksums.yml', __dir__)
CHECKSUMS =
YAML.load_file(CHECKSUMS_FILE)
VERSION =
CHECKSUMS.fetch('version')
RETRIES =
3
RETRY_DELAY =
1

Class Method Summary collapse

Class Method Details

.download(file_name: Class.new.extend(Cobhan).library_file_name(LIB_NAME), dir: File.join(ROOT_DIR, 'lib/asherah/native')) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'ext/asherah/native_file.rb', line 20

def download(
  file_name: Class.new.extend(Cobhan).library_file_name(LIB_NAME),
  dir: File.join(ROOT_DIR, 'lib/asherah/native')
)
  file_path = File.join(dir, file_name)
  if File.exist?(file_path)
    puts "#{file_path} already exists ... skipping download"
    return
  end

  checksum = CHECKSUMS.fetch(file_name) do
    abort "Unsupported platform #{RUBY_PLATFORM}"
  end

  content = download_content(file_name)

  sha256 = Digest::SHA256.hexdigest(content)
  abort "Could not verify checksum of #{file_name}" if sha256 != checksum

  FileUtils.mkdir_p(dir)
  File.binwrite(file_path, content)
end