Class: RPM::File::Header
- Inherits:
-
Object
- Object
- RPM::File::Header
- Includes:
- Cabin::Inspectable
- Defined in:
- lib/arr-pm/file/header.rb
Constant Summary collapse
- HEADER_SIGNED_TYPE =
5- HEADER_MAGIC =
Ruby 2 forces all strings to be UTF-8, so “x01” becomes “u0001” which is two bytes 00 01 which is not what we want. I can’t find a sane way to create a string without this madness in Ruby 2, so let’s just pack two 4-byte integers and go about our day.
"\x8e\xad\xe8\x01\x00\x00\x00\x00"- HEADER_HEADER_LENGTH =
magic + index_count + data_length
HEADER_MAGIC.length + 4 + 4
- TAG_ENTRY_SIZE =
tag id, type, offset, count == 16 bytes
16
Instance Attribute Summary collapse
-
#data_length ⇒ Object
rpmlib calls this field ‘dl’ unhelpfully.
-
#index_count ⇒ Object
rpmlib calls this field ‘il’ unhelpfully.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#magic ⇒ Object
8-byte string magic.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(file) ⇒ Header
constructor
A new instance of Header.
- #read ⇒ Object
-
#validate ⇒ Object
def write.
-
#write ⇒ Object
def read.
Constructor Details
#initialize(file) ⇒ Header
Returns a new instance of Header.
29 30 31 32 33 34 |
# File 'lib/arr-pm/file/header.rb', line 29 def initialize(file) @file = file @inspectables = [:@length, :@index_count, :@data_length] @tags = [] end |
Instance Attribute Details
#data_length ⇒ Object
rpmlib calls this field ‘dl’ unhelpfully
12 13 14 |
# File 'lib/arr-pm/file/header.rb', line 12 def data_length @data_length end |
#index_count ⇒ Object
rpmlib calls this field ‘il’ unhelpfully
11 12 13 |
# File 'lib/arr-pm/file/header.rb', line 11 def index_count @index_count end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
8 9 10 |
# File 'lib/arr-pm/file/header.rb', line 8 def length @length end |
#magic ⇒ Object
8-byte string magic
10 11 12 |
# File 'lib/arr-pm/file/header.rb', line 10 def magic @magic end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
7 8 9 |
# File 'lib/arr-pm/file/header.rb', line 7 def @tags end |
Instance Method Details
#read ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/arr-pm/file/header.rb', line 36 def read # TODO(sissel): update the comments here to reflect learnings about rpm # internals # At this point assume we've read and consumed the lead and signature. #len = @rpm.signature.index_length + @rpm.signature # # header size is # ( @rpm.signature.index_length * size of a header entry ) # + @rpm.signature.data_length # # header 'entries' are an # int32 (tag id), int32 (tag type), int32 (offset), uint32 (count) # # len = sizeof(il) + sizeof(dl) + (il * sizeof(struct entryInfo_s)) + dl; # See rpm's header.c, the headerLoad method function for reference. # Header always starts with HEADER_MAGIC + index_count(2bytes) + # data_length(2bytes) data = @file.read(HEADER_HEADER_LENGTH).unpack("a8NN") # TODO(sissel): @index_count is really a count, rename? @magic, @index_count, @data_length = data validate @index_size = @index_count * TAG_ENTRY_SIZE tag_data = @file.read(@index_size) data = @file.read(@data_length) (0 ... @index_count).each do |i| offset = i * TAG_ENTRY_SIZE entry_data = tag_data[i * TAG_ENTRY_SIZE, TAG_ENTRY_SIZE] entry = entry_data.unpack("NNNN") entry << data tag = ::RPM::File::Tag.new(*entry) @tags << tag end # each index @length = HEADER_HEADER_LENGTH + @index_size + @data_length end |
#validate ⇒ Object
def write
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/arr-pm/file/header.rb', line 82 def validate # TODO(sissel): raise real exceptions if @magic != ::RPM::File::Header::HEADER_MAGIC raise "Header magic did not match; got #{@magic.inspect}, " \ "expected #{::RPM::File::Header::HEADER_MAGIC.inspect}" end #if !(0..32).include?(@index_count) #raise "Invalid 'index_count' value #{@index_count}, expected to be in range [0..32]" #end #if !(0..8192).include?(@data_length) #raise "Invalid 'data_length' value #{@data_length}, expected to be in range [0..8192]" #end end |
#write ⇒ Object
def read
75 76 77 78 79 80 |
# File 'lib/arr-pm/file/header.rb', line 75 def write raise "not implemented yet" # Sort tags by type (integer value) # emit all tags in order # then emit all data segments in same order end |