func RemoveFile(filename string) error {
	err := os.RemoveAll(filename)
	if err != nil {
		return err
	}
	err = os.RemoveAll(filename + tempSuffix)
	if err != nil {
		return err
	}
	return nil
}
RemoveFile removes an atomic file from disk, along with any uncommitted
or temporary files.
package persist
import (
	"encoding/base32"
	"errors"
	"os"
	"path/filepath"
	"sync"
	"github.com/NebulousLabs/fastrand"
)
const (
	persistDir = "persist"
	tempSuffix = "_temp"
)
var (
	ErrBadFilenameSuffix = errors.New("filename suffix not allowed")
	ErrBadHeader = errors.New("wrong header")
	ErrBadVersion = errors.New("incompatible version")
	ErrFileInUse = errors.New("another thread is saving or loading this file")
)
var (
	activeFiles   = make(map[string]struct{})
	activeFilesMu sync.Mutex
)
type Metadata struct {
	Header, Version string
}
func RandomSuffix() string {
	str := base32.StdEncoding.EncodeToString(fastrand.Bytes(20))
	return str[:20]
}
type safeFile struct {
	*os.File
	finalName string
}
func (sf *safeFile) CommitSync() error {
	if err := sf.Sync(); err != nil {
		return err
	}
	if err := sf.Close(); err != nil {
		return err
	}
	return os.Rename(sf.finalName+"_temp", sf.finalName)
}
func NewSafeFile(filename string) (*safeFile, error) {
	file, err := os.Create(filename + tempSuffix)
	if err != nil {
		return nil, err
	}
	absFilename, err := filepath.Abs(filename)
	if err != nil {
		return nil, err
	}
	return &safeFile{file, absFilename}, nil
}