func EnsureLeadingSlash(dir string) string {
	if hasLeadingSlash.MatchString(dir) {
		return dir
	}
	return "/" + dir
}
EnsureLeadingSlash is like EnsureTrailingSlash except that it adds the leading slash if needed.
package utils
import (
	"errors"
	"fmt"
	"io"
	"regexp"
	"strings"
	"time"
	"github.com/c2fo/vfs/v6"
)
const (
	ErrBadAbsFilePath = "absolute file path is invalid - must include leading slash and may not include trailing slash"
	ErrBadRelFilePath = "relative file path is invalid - may not include leading or trailing slashes"
	ErrBadAbsLocationPath = "absolute location path is invalid - must include leading and trailing slashes"
	ErrBadRelLocationPath = "relative location path is invalid - may not include leading slash but must include trailing slash"
	TouchCopyMinBufferSize = 262144
)
var hasTrailingSlash = regexp.MustCompile("/$")
var hasLeadingSlash = regexp.MustCompile("^/")
func RemoveTrailingSlash(path string) string {
	return strings.TrimRight(path, "/")
}
func RemoveLeadingSlash(path string) string {
	return strings.TrimLeft(path, "/")
}
func ValidateAbsoluteFilePath(name string) error {
	if !strings.HasPrefix(name, "/") || strings.HasSuffix(name, "/") {
		return errors.New(ErrBadAbsFilePath)
	}
	return nil
}
func ValidateRelativeFilePath(name string) error {
	if name == "" || strings.HasPrefix(name, "/") || strings.HasSuffix(name, "/") {
		return errors.New(ErrBadRelFilePath)
	}
	return nil
}
func ValidateAbsoluteLocationPath(name string) error {
	if !strings.HasPrefix(name, "/") || !strings.HasSuffix(name, "/") {
		return errors.New(ErrBadAbsLocationPath)
	}
	return nil
}
func ValidateRelativeLocationPath(name string) error {
	if strings.HasPrefix(name, "/") || !strings.HasSuffix(name, "/") {
		return errors.New(ErrBadRelLocationPath)
	}
	return nil
}
func GetFileURI(f vfs.File) string {
	return fmt.Sprintf("%s://%s%s", f.Location().FileSystem().Scheme(), f.Location().Volume(), f.Path())
}
func GetLocationURI(l vfs.Location) string {
	return fmt.Sprintf("%s://%s%s", l.FileSystem().Scheme(), l.Volume(), l.Path())
}
func EnsureTrailingSlash(dir string) string {
	if hasTrailingSlash.MatchString(dir) {
		return dir
	}
	return dir + "/"
}