    # File lib/rubygems/indexer.rb, line 93
      def build_indicies(index)
        progress = ui.progress_reporter index.size,
                                        "Generating quick index gemspecs for #{index.size} gems",
                                        "Complete"

        index.each do |original_name, spec|
          spec_file_name = "#{original_name}.gemspec.rz"
          yaml_name = File.join @quick_dir, spec_file_name
          marshal_name = File.join @quick_marshal_dir, spec_file_name

          yaml_zipped = Gem.deflate spec.to_yaml
          open yaml_name, 'wb' do |io| io.write yaml_zipped end

          marshal_zipped = Gem.deflate Marshal.dump(spec)
          open marshal_name, 'wb' do |io| io.write marshal_zipped end

          progress.updated original_name
        end

        progress.done

        say "Generating specs index"

        open @specs_index, 'wb' do |io|
          specs = index.sort.map do |_, spec|
            platform = spec.original_platform
            platform = Gem::Platform::RUBY if platform.nil?
            [spec.name, spec.version, platform]
          end

          specs = compact_specs specs

          Marshal.dump specs, io
        end

        say "Generating latest specs index"

        open @latest_specs_index, 'wb' do |io|
          specs = index.latest_specs.sort.map do |spec|
            [spec.name, spec.version, spec.original_platform]
          end

          specs = compact_specs specs

          Marshal.dump specs, io
        end

        say "Generating quick index"

        quick_index = File.join @quick_dir, 'index'
        open quick_index, 'wb' do |io|
          io.puts index.sort.map { |_, spec| spec.original_name }
        end

        say "Generating latest index"

        latest_index = File.join @quick_dir, 'latest_index'
        open latest_index, 'wb' do |io|
          io.puts index.latest_specs.sort.map { |spec| spec.original_name }
        end

        say "Generating Marshal master index"

        open @marshal_index, 'wb' do |io|
          io.write index.dump
        end

        progress = ui.progress_reporter index.size,
                                        "Generating YAML master index for #{index.size} gems (this may take a while)",
                                        "Complete"

        open @master_index, 'wb' do |io|
          io.puts "--- !ruby/object:#{index.class}"
          io.puts "gems:"

          gems = index.sort_by { |name, gemspec| gemspec.sort_obj }
          gems.each do |original_name, gemspec|
            yaml = gemspec.to_yaml.gsub(/^/, '    ')
            yaml = yaml.sub(/\A    ---/, '') # there's a needed extra ' ' here
            io.print "  #{original_name}:"
            io.puts yaml

            progress.updated original_name
          end
        end

        progress.done

        say "Compressing indicies"
        # use gzip for future files.

        compress quick_index, 'rz'
        paranoid quick_index, 'rz'

        compress latest_index, 'rz'
        paranoid latest_index, 'rz'

        compress @marshal_index, 'Z'
        paranoid @marshal_index, 'Z'

        compress @master_index, 'Z'
        paranoid @master_index, 'Z'

        gzip @specs_index
        gzip @latest_specs_index
      end