code: func unprotectedWriteToFragment(f *fragment, bm *roaring.Bitmap) (n int64, err error) { // nolint: interfacer
  
  	completeMessage := fmt.Sprintf("fragment: snapshot complete %s/%s/%s/%d", f.index, f.field, f.view, f.shard)
  	start := time.Now()
  	defer track(start, completeMessage, f.stats, f.Logger)
  
  	// Create a temporary file to snapshot to.
  	snapshotPath := f.path + snapshotExt
  	file, err := os.Create(snapshotPath)
  	if err != nil {
  		return n, fmt.Errorf("create snapshot file: %s", err)
  	}
  	defer file.Close()
  
  	// Write storage to snapshot.
  	bw := bufio.NewWriter(file)
  	if n, err = bm.WriteTo(bw); err != nil {
  		return n, fmt.Errorf("snapshot write to: %s", err)
  	}
  
  	if err := bw.Flush(); err != nil {
  		return n, fmt.Errorf("flush: %s", err)
  	}
  
  	// Close current storage.
  	if err := f.closeStorage(); err != nil {
  		return n, fmt.Errorf("close storage: %s", err)
  	}
  
  	// Move snapshot to data file location.
  	if err := os.Rename(snapshotPath, f.path); err != nil {
  		return n, fmt.Errorf("rename snapshot: %s", err)
  	}
  
  	// Reopen storage.
  	if err := f.openStorage(); err != nil {
  		return n, fmt.Errorf("open storage: %s", err)
  	}
  
  	// Reset operation count.
  	f.opN = 0
  
  	return n, nil
  }
docs: // unprotectedWriteToFragment writes the fragment f with bm as the data. It is unprotected, and
  // f.mu must be locked when calling it.