def readpartial(length = nil)
      if length.nil? && @buffer.length > 0
        slice = @buffer
        @buffer = ""
      else
        unless finished_reading? || (length && length <= @buffer.length)
          @connection.readpartial(length ? length - @buffer.length : @connection.buffer_size)
        end

        if length
          slice = @buffer.slice!(0, length)
        else
          slice = @buffer
          @buffer = ""
        end
      end

      slice && slice.length == 0 ? nil : slice
    end
def readpartial(length = nil)
      if length.nil? && @buffer.length > 0
        slice = @buffer
        @buffer = ""
      else
        unless finished_reading? || (length && length <= @buffer.length)
          @connection.readpartial(length ? length - @buffer.length : @connection.buffer_size)
        end

        if length
          slice = @buffer.slice!(0, length)
        else
          slice = @buffer
          @buffer = ""
        end
      end

      slice && slice.length == 0 ? nil : slice
    end
Read a string up to the given number of bytes, blocking until some
 data is available but returning immediately if some data is available