lib/care.rb
# Reads the requested page from the given IO
#
# @param io[IO] the IO to read from
# @param page_i[Integer] which page (zero-based) to read
Reads the requested page from the given IO
Reads the requested page from the given IO
def read_page(io, page_i)
      Measurometer.increment_counter('format_parser.parser.Care.page_reads_from_upsteam', 1)
      io.seek(page_i * @page_size)
      read_result = Measurometer.instrument('format_parser.Care.read_page') { io.read(@page_size) }
      if read_result.nil?
        if @lowest_known_empty_page.nil? || @lowest_known_empty_page > page_i
          @lowest_known_empty_page = page_i
        end
      elsif read_result.bytesize < @page_size
        @lowest_known_empty_page = page_i + 1
      end
      read_result
    end
def read_page ( io , page_i ) Measurometer . increment_counter ( 'format_parser.parser.Care.page_reads_from_upsteam' , 1 ) io . seek ( page_i * @page_size ) read_result = Measurometer . instrument ( 'format_parser.Care.read_page' ) { io . read ( @page_size ) } if read_result . nil? if @lowest_known_empty_page . nil? || @lowest_known_empty_page > page_i @lowest_known_empty_page = page_i end elsif read_result . bytesize < @page_size @lowest_known_empty_page = page_i + 1 end read_result end
Reads the requested page from the given IO
Reads the requested page from the given IO
# If the read went past the end of the IO the read result will be nil, # so we know our IO is exhausted here # If we read less than we initially wanted we know there are no pages # to read following this one, so we can also optimize
io
the IO to read from
the IO to read from
page_i
which page (zero-based) to read
which page ( zero - based ) to read