Class: Rupert::RPM::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/rupert/rpm/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, type, offset, count) ⇒ Entry

Initializes a new index entry.

Parameters:

  • tag (String)

    4 byte entry tag (semantic data type)

  • type (String)

    4 byte entry data format

  • offset (String)

    4 byte pointer to data in the index store

  • count (String)

    4 byte number of data items held by the entry



10
11
12
# File 'lib/rupert/rpm/entry.rb', line 10

def initialize(tag, type, offset, count)
  @tag, @type, @offset, @count = tag, type, offset, count
end

Instance Attribute Details

#tagObject

Returns the value of attribute tag.



14
15
16
# File 'lib/rupert/rpm/entry.rb', line 14

def tag
  @tag
end

Instance Method Details

#resolve(store) ⇒ Object

Fetches referenced data from a store.

An entry contains only information about a piece of data, but not the actual data. In essence, it behaves more or less like a pointer, which contains the address at which data is available.

This method behaves exactly like pointer dereference, i.e. it returns the actual data at the address held by the entry itself. In addition, data is not returned in raw form; instead, it is returned in the format declared in the entry itself. The available RPM formats are the following:

  • NULL

  • CHAR

  • INT8

  • INT16

  • INT32

  • INT64 (not supported yet even in rpmlib?)

  • STRING

  • BIN

  • STRING_ARRAY

  • I18NSTRING

which are in turn mapped in Ruby with:

  • nil

  • (Array of) String of length 1

  • (Array of) Fixnum

  • (Array of) Fixnum

  • (Array of) Fixnum

  • (Array of) Fixnum/Bignum

  • String of arbitrary length

  • String of arbitrary length, 8-bit ASCII encoded

  • Array of String

  • Array of String

NOTE: The store is sought to retrieve data. Do not make any assumptions on IO’s pointer state after method call. If you need to perform subsequent operations on the IO that require a particular cursor position, seek the IO to wanted position before performing the operation.

Parameters:

  • store (IO)

    raw data store, represented by an IO object

Returns:

  • (Object)

    data referenced by this entry, in whatever format the entry prescribe



61
62
63
64
# File 'lib/rupert/rpm/entry.rb', line 61

def resolve(store)
  store.seek(@offset, IO::SEEK_SET)
  read_and_convert(@type, store)
end