Class: MooTool::Img4::File

Inherits:
Object
  • Object
show all
Defined in:
lib/mootool/models/img4.rb

Overview

An instance of a IMG4 file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ File

Returns a new instance of File.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mootool/models/img4.rb', line 14

def initialize(path)
  @path = path
  der = ::File.binread(path)
  @data = OpenSSL::ASN1.decode(der)

  case @data.first.value
  when 'IM4P'
    @type = @data.value[1].value
    @build = @data.value[2].value
    @payload = MooTool::Decompressor.new(@data.value[3].value).value
  when 'IMG4', 'IM4M'
    raise 'Not implemented'
  else
    raise "Unknown IMG4 type #{@data.first.value}"
  end

  @manifest = Digest.new(@payload) if @payload.start_with?('IM4M')
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



12
13
14
# File 'lib/mootool/models/img4.rb', line 12

def manifest
  @manifest
end

#payloadObject (readonly)

Returns the value of attribute payload.



12
13
14
# File 'lib/mootool/models/img4.rb', line 12

def payload
  @payload
end

Instance Method Details

#basenameObject



41
42
43
44
45
# File 'lib/mootool/models/img4.rb', line 41

def basename
  basename = ::File.basename(@path)
  extension = ::File.extname(basename)
  "#{basename.chomp(extension)}.#{@type}"
end

#extract_payloadObject



47
48
49
50
# File 'lib/mootool/models/img4.rb', line 47

def extract_payload
  output_path = ::File.join(::File.dirname(@path), basename)
  ::File.write(output_path, @payload)
end

#manifest?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mootool/models/img4.rb', line 37

def manifest?
  !@manifest.nil?
end

#payload?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mootool/models/img4.rb', line 33

def payload?
  !@payload.nil?
end