Class: ArrPM::V2::HeaderHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/arr-pm/v2/header_header.rb

Overview

The header of an rpm has … a header. Funky naming :)

Constant Summary collapse

MAGIC =
[ 0x8e, 0xad, 0xe8 ]
MAGIC_LENGTH =
MAGIC.count

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bytesizeObject

Returns the value of attribute bytesize.



12
13
14
# File 'lib/arr-pm/v2/header_header.rb', line 12

def bytesize
  @bytesize
end

#entriesObject

Returns the value of attribute entries.



12
13
14
# File 'lib/arr-pm/v2/header_header.rb', line 12

def entries
  @entries
end

#versionObject

Returns the value of attribute version.



12
13
14
# File 'lib/arr-pm/v2/header_header.rb', line 12

def version
  @version
end

Class Method Details

.validate_magic(value) ⇒ Object



33
34
35
# File 'lib/arr-pm/v2/header_header.rb', line 33

def self.validate_magic(value)
  raise ArrPM::V2::Error::InvalidHeaderMagicValue, value if value != MAGIC
end

Instance Method Details

#dumpObject



29
30
31
# File 'lib/arr-pm/v2/header_header.rb', line 29

def dump
  [magic, 1, 0, @entries, @bytesize].pack("a3Ca4NN")
end

#load(io) ⇒ Object



14
15
16
17
# File 'lib/arr-pm/v2/header_header.rb', line 14

def load(io)
  data = io.read(16)
  parse(data)
end

#parse(data) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/arr-pm/v2/header_header.rb', line 19

def parse(data)
  magic, version, reserved, entries, bytesize = data.unpack("a3Ca4NN")
  self.class.validate_magic(magic.bytes)

  @version = version
  @entries = entries
  @bytesize = bytesize
  nil
end