func (b Builder) buildV1(output io.Writer) error {
	allContents := b.sortedContents()
	b1 := &indexBuilderV1{
		packBlobIDOffsets: map[blob.ID]uint32{},
		keyLength:         -1,
		entryLength:       v1EntryLength,
		entryCount:        len(allContents),
	}

	w := bufio.NewWriter(output)

	// prepare extra data to be appended at the end of an index.
	extraData := b1.prepareExtraData(allContents)

	// write header
	header := make([]byte, v1HeaderSize)
	header[0] = 1 // version
	header[1] = byte(b1.keyLength)
	binary.BigEndian.PutUint16(header[2:4], uint16(b1.entryLength))
	binary.BigEndian.PutUint32(header[4:8], uint32(b1.entryCount))

	if _, err := w.Write(header); err != nil {
		return errors.Wrap(err, "unable to write header")
	}

	// write all sorted contents.
	entry := make([]byte, b1.entryLength)

	for _, it := range allContents {
		if err := b1.writeEntry(w, it, entry); err != nil {
			return errors.Wrap(err, "unable to write entry")
		}
	}

	if _, err := w.Write(extraData); err != nil {
		return errors.Wrap(err, "error writing extra data")
	}

	return errors.Wrap(w.Flush(), "error flushing index")
}
// buildV1 writes the pack index to the provided output.
buildV1 writes the pack index to the provided output.
// buildV1 writes the pack index to the provided output .
func (b Builder) buildV1(output io.Writer) error {
	allContents := b.sortedContents()
	b1 := &indexBuilderV1{
		packBlobIDOffsets: map[blob.ID]uint32{},
		keyLength:         -1,
		entryLength:       v1EntryLength,
		entryCount:        len(allContents),
	}
	w := bufio.NewWriter(output)
	extraData := b1.prepareExtraData(allContents)
	header := make([]byte, v1HeaderSize)
	header[0] = 1 
	header[1] = byte(b1.keyLength)
	binary.BigEndian.PutUint16(header[2:4], uint16(b1.entryLength))
	binary.BigEndian.PutUint32(header[4:8], uint32(b1.entryCount))
	if _, err := w.Write(header); err != nil {
		return errors.Wrap(err, "unable to write header")
	}
	entry := make([]byte, b1.entryLength)
	for _, it := range allContents {
		if err := b1.writeEntry(w, it, entry); err != nil {
			return errors.Wrap(err, "unable to write entry")
		}
	}
	if _, err := w.Write(extraData); err != nil {
		return errors.Wrap(err, "error writing extra data")
	}
	return errors.Wrap(w.Flush(), "error flushing index")
}
func ( b Builder ) buildV1 ( output io . Writer ) error { allContents := b . sortedContents ( ) b1 := & indexBuilderV1 { packBlobIDOffsets : map [ blob . ID ] uint32 { } , keyLength : - 1 , entryLength : v1EntryLength , entryCount : len ( allContents ) , } w := bufio . NewWriter ( output ) extraData := b1 . prepareExtraData ( allContents ) header := make ( [ ] byte , v1HeaderSize ) header [ 0 ] = 1 header [ 1 ] = byte ( b1 . keyLength ) binary . BigEndian . PutUint16 ( header [ 2 : 4 ] , uint16 ( b1 . entryLength ) ) binary . BigEndian . PutUint32 ( header [ 4 : 8 ] , uint32 ( b1 . entryCount ) ) if _ , err := w . Write ( header ) ; err != nil { return errors . Wrap ( err , " " ) } entry := make ( [ ] byte , b1 . entryLength ) for _ , it := range allContents { if err := b1 . writeEntry ( w , it , entry ) ; err != nil { return errors . Wrap ( err , " " ) } } if _ , err := w . Write ( extraData ) ; err != nil { return errors . Wrap ( err , " " ) } return errors . Wrap ( w . Flush ( ) , " " ) }
buildV1 writes the pack index to the provided output.
buildV1 writes the pack index to the provided output .
// prepare extra data to be appended at the end of an index. // write header // version // write all sorted contents.