Class: HexaPDF::Type::ObjectStream::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/type/object_stream.rb

Overview

Holds all necessary information to load objects for an object stream.

Instance Method Summary collapse

Constructor Details

#initialize(stream_data, oids, offsets) ⇒ Data

Initializes the data object with the needed values.



80
81
82
83
84
# File 'lib/hexapdf/type/object_stream.rb', line 80

def initialize(stream_data, oids, offsets)
  @tokenizer = Tokenizer.new(StringIO.new(stream_data))
  @offsets = offsets
  @oids = oids
end

Instance Method Details

#object_by_index(index) ⇒ Object

Returns the object specified by the given index together with its object number.

Objects are not pre-loaded, so every time this method is invoked the associated stream data is parsed and a new object returned.



90
91
92
93
94
95
96
97
# File 'lib/hexapdf/type/object_stream.rb', line 90

def object_by_index(index)
  if index >= @offsets.size || index < 0
    raise ArgumentError, "Invalid index into object stream given"
  end

  @tokenizer.pos = @offsets[index]
  [@tokenizer.next_object, @oids[index]]
end