code: func (bv *BitVector) Write(d store.Directory, name string, ctx store.IOContext) (err error) {
  	assert(reflect.TypeOf(d).Name() != "CompoundFileDirectory")
  	var output store.IndexOutput
  	if output, err = d.CreateOutput(name, ctx); err != nil {
  		return err
  	}
  	defer func() {
  		err = mergeError(err, output.Close())
  	}()
  
  	if err = output.WriteInt(-2); err != nil {
  		return err
  	}
  	if err = codec.WriteHeader(output, CODEC, BV_VERSION_CURRENT); err != nil {
  		return err
  	}
  	if bv.isSparse() {
  		// sparse bit-set more efficiently saved as d-gaps.
  		err = bv.writeClearedDgaps(output)
  	} else {
  		err = bv.writeBits(output)
  	}
  	if err != nil {
  		return err
  	}
  	if err = codec.WriteFooter(output); err != nil {
  		return err
  	}
  	bv.assertCount()
  	return nil
  }
docs: /*
  Writes this vector to the file name in Directory d, in a format that
  can be read by the constructor BitVector(Directory, String, IOContext)
  */