# File lib/rubytorrent/package.rb, line 166
  def first_gap(domain=@domain)
    start = domain.first
    endd = nil
    excl = nil
    @ranges.each do |r|
      next if r.last < start

      if r.first > start # found a gap
        if r.first < domain.last
          return AwesomeRange.new(start, r.first, false)
        else # r.first >= domain.last, so use domain's exclusion
          return AwesomeRange.new(start, domain.last, domain.exclude_end?)
        end
      else # r.first <= start
        start = r.last unless r.last < start
        break if start > domain.last
      end
    end

    if (start >= domain.last)
      ## entire domain was covered
      nil
    else
      ## tail end of the domain uncovered
      AwesomeRange.new(start, domain.last, domain.exclude_end?)
    end
  end