import "github.com/c2fo/vfs/v7/utils"var (
// ErrBadAbsFilePath is returned when a file path is not absolute
ErrBadAbsFilePath = errors.New("absolute file path is invalid - must include leading slash and may not include trailing slash")
// ErrBadRelFilePath is returned when a file path is not relative
ErrBadRelFilePath = errors.New("relative file path is invalid - may not include leading or trailing slashes")
// ErrBadAbsLocationPath is returned when a file path is not absolute
ErrBadAbsLocationPath = errors.New("absolute location path is invalid - must include leading and trailing slashes")
// ErrBadRelLocationPath is returned when a file path is not relative
ErrBadRelLocationPath = errors.New("relative location path is invalid - may not include leading slash but must include trailing slash")
// ErrBadPrefix is returned when a prefix is not relative or ends in / or is empty
ErrBadPrefix = errors.New("prefix is invalid - may not include leading or trailing slashes and may not be empty")
)const (
// TouchCopyMinBufferSize min buffer size used in TouchCopyBuffered in bytes
TouchCopyMinBufferSize = 262144
)func EnsureLeadingSlash(dir string) stringEnsureLeadingSlash is like EnsureTrailingSlash except that it adds the leading slash if needed.
func EnsureTrailingSlash(dir string) stringEnsureTrailingSlash is like AddTrailingSlash but will only ever use / since it's use for web uri's, never a Windows OS path.
func GetFileURI(f vfs.File) stringGetFileURI returns a File URI
func GetLocationURI(l vfs.Location) stringGetLocationURI returns a Location URI
func PathToURI(p string) (string, error)PathToURI takes a relative or absolute path and returns an OS URI.
- We assume non-scheme path is an OS File or Location.
- We assume URI authority is empty.
- We assume relative paths are relative to the pwd (program's working directory)
- We assume an empty path is equal to the root path: "/"
| original path | becomes URI |
|---|---|
| /absolute/path/to/file.txt | file:///absolute/path/to/file.txt |
| /some/absolute/path/ | file:///absolute/path/ |
| relative/path/to/file.txt | file:///absolute/path/with/relative/path/to/file.txt |
| relative/path/ | file:///absolute/path/with/relative/path/ |
func RemoveLeadingSlash(path string) stringRemoveLeadingSlash removes leading slash, if any
func RemoveTrailingSlash(path string) stringRemoveTrailingSlash removes trailing slash, if any
func TouchCopy(writer io.Writer, reader io.Reader) errorTouchCopy is a wrapper around io.Copy which ensures that even empty source files (reader) will get written as an empty file. It guarantees a Write() call on the target file. Deprecated: Use TouchCopyBuffer Instead
func TouchCopyBuffered(writer io.Writer, reader io.Reader, bufferSize int) errorTouchCopyBuffered is a wrapper around io.CopyBuffer which ensures that even empty source files (reader) will get written as an empty file. It guarantees a Write() call on the target file. bufferSize is in bytes and if is less than TouchCopyMinBufferSize will result in a buffer of size TouchCopyMinBufferSize bytes. If bufferSize is > TouchCopyMinBufferSize it will result in a buffer of size bufferSize bytes
func UpdateLastModifiedByMoving(file vfs.File) errorUpdateLastModifiedByMoving is used by some backends' Touch() method when a file already exists.
func ValidateAbsoluteFilePath(name string) errorValidateAbsoluteFilePath ensures that a file path has a leading slash but not a trailing slash
func ValidateAbsoluteLocationPath(name string) errorValidateAbsoluteLocationPath ensure that a file path has both leading and trailing slashes
func ValidatePrefix(prefix string) errorValidatePrefix ensures that a prefix path has neither leading nor trailing slashes may not be empty but unlike relative file path, may be simply "."
func ValidateRelativeFilePath(name string) errorValidateRelativeFilePath ensures that a file path has neither leading nor trailing slashes
func ValidateRelativeLocationPath(name string) errorValidateRelativeLocationPath ensure that a file path has no leading slash but has a trailing slash
type Authority struct {
}Authority represents host, port and userinfo (user/pass) in a URI
func NewAuthority(authority string) (Authority, error)NewAuthority initializes Authority struct by parsing authority string.
func (a Authority) Host() stringHost returns the host portion of an authority
func (a Authority) HostPortStr() stringHostPortStr returns a concatenated string of host and port from authority, separated by a colon, ie "host.com:1234"
func (a Authority) Port() uint16Port returns the port portion of an authority
func (a Authority) String() stringString() returns a string representation of authority. It does not include password per https://tools.ietf.org/html/rfc3986#section-3.2.1
Applications should not render as clear text any data after the first colon (":") character found within a userinfo
subcomponent unless the data after the colon is the empty string (indicating no password).
func (a Authority) UserInfo() UserInfoUserInfo returns the userinfo section of authority. userinfo is username and password(deprecated).
type UserInfo struct {
}UserInfo represents user/pass portion of a URI
func (u UserInfo) Password() stringPassword returns the password of a URI UserInfo. May be an empty string.
func (u UserInfo) Username() stringUsername returns the username of a URI UserInfo. May be an empty string.