code: func (b *Builder) Build() (*FileSorter, error) {
  	// Sanity checks
  	if b.sc == nil {
  		return nil, errors.New("StatementContext is nil")
  	}
  	if b.keySize != len(b.byDesc) {
  		return nil, errors.New("mismatch in key size and byDesc slice")
  	}
  	if b.keySize <= 0 {
  		return nil, errors.New("key size is not positive")
  	}
  	if b.valSize <= 0 {
  		return nil, errors.New("value size is not positive")
  	}
  	if b.bufSize <= 0 {
  		return nil, errors.New("buffer size is not positive")
  	}
  	_, err := os.Stat(b.tmpDir)
  	if err != nil {
  		if os.IsNotExist(err) {
  			return nil, errors.New("tmpDir does not exist")
  		}
  		return nil, errors.Trace(err)
  	}
  
  	rh := &rowHeap{sc: b.sc,
  		ims:    make([]*item, 0),
  		byDesc: b.byDesc,
  	}
  
  	return &FileSorter{sc: b.sc,
  		keySize: b.keySize,
  		valSize: b.valSize,
  		bufSize: b.bufSize,
  		buf:     make([]*comparableRow, 0, b.bufSize),
  		files:   make([]string, 0),
  		byDesc:  b.byDesc,
  		rowHeap: rh,
  		tmpDir:  b.tmpDir,
  		fds:     make([]*os.File, 0),
  	}, nil
  }
docs: // Build creates a FileSorter instance using given data.