Class: Arv::Collection::LocatorList

Inherits:
Object
  • Object
show all
Defined in:
lib/arvados/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(locators) ⇒ LocatorList

LocatorList efficiently builds LocatorSegments from a stream manifest.



176
177
178
179
180
181
182
183
# File 'lib/arvados/collection.rb', line 176

def initialize(locators)
  next_start = 0
  @ranges = locators.map do |loc_s|
    new_range = LocatorRange.new(loc_s, next_start)
    next_start = new_range.end
    new_range
  end
end

Instance Method Details

#segment(start_pos, length) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/arvados/collection.rb', line 185

def segment(start_pos, length)
  # Return a LocatorSegment that captures `length` bytes from `start_pos`.
  start_index = search_for_byte(start_pos)
  if length == 0
    end_index = start_index
  else
    end_index = search_for_byte(start_pos + length - 1, start_index)
  end
  seg_ranges = @ranges[start_index..end_index]
  Struct::LocatorSegment.new(seg_ranges.map(&:locator),
                             start_pos - seg_ranges.first.begin,
                             length)
end