file

package
v0.0.0-...-9202be0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package file is a package for dealing with strongly typed paths and files in an OS agnostic manner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(ctx context.Context, dst Path, src Path) error

Copy copies src to dst, replacing any existing file at dst.

func IsJunction

func IsJunction(path Path) bool

IsJunction returns false as junctions are not supported by this platform.

func Junction

func Junction(link, target Path) error

Junction calls through to Symlink as junctions are not supported by this platform.

func Link(link, target Path) error

Link creates a new hard-link at link to target.

func Mkdir

func Mkdir(dir Path) error

Mkdir creates the directory specified.

func Mkfile

func Mkfile(p Path) error

Mkfile creates an empty file ath the specified path.

func Move

func Move(dst, src Path) error

Move moves the file at src to dst.

func Relink(link, target Path, method func(link, target Path) error) error

Relink repoints link to target using the provided linking function.

func Remove

func Remove(f Path) error

Remove deletes the file at f.

func RemoveAll

func RemoveAll(f Path) error

RemoveAll deletes the path and all chidren rooted at f.

func SanitizePath

func SanitizePath(p string) string

SanitizePath returns the path p with illegal file path characters replaced with '-'.

func Symlink(link, target Path) error

Symlink creates a new symbolic-link at link to target.

func Unzip

func Unzip(ctx context.Context, archive string, outputDir string) error

Unzip extract a ZIP archive, creating all elements under outputDir

func ZIP

func ZIP(out io.Writer, in Path) error

ZIP zips the given input file/directory to the given writer.

Types

type Path

type Path struct {
	// contains filtered or unexported fields
}

Path is a clean absolute path with platform specific separators.

func Abs

func Abs(path string) Path

Abs is the primary constructor of new Path objects from strings using either the / or system separator.

func ExecutablePath

func ExecutablePath() Path

ExecutablePath returns the path to the running executable.

func FindExecutable

func FindExecutable(name string) (Path, error)

FindExecutable searches the system search path for the named binary, and returns a non empty Path if found. OS executable file extensions (".exe") are automatically considered when searching.

func Temp

func Temp() (Path, error)

Temp creates a new temp file and returns its path.

func TempWithExt

func TempWithExt(name string, ext string) (Path, error)

TempWithExt creates a new temp file with the given name and extension and returns its path.

func (Path) Basename

func (p Path) Basename() string

Basename returns the name part of the path (without directories).

func (Path) ChangeExt

func (p Path) ChangeExt(ext string) Path

ChangeExt returns a new Path with the extension changed to ext. ext should being with a '.' to change extension, or be an empty string to remove the extension.

func (Path) Contains

func (p Path) Contains(other Path) bool

Contains returns true if this directory contains the other.

func (Path) Exists

func (p Path) Exists() bool

Exists returns true if this File exists.

func (Path) Ext

func (p Path) Ext() string

Ext returns the extension of the path, including the '.', or an empty string if the path has no extension.

func (Path) Files

func (p Path) Files() PathList

Files reads the list of files in path.

func (Path) Glob

func (p Path) Glob(pattern ...string) PathList

Glob adds each pattern to the path in turn, and uses filepath.Glob to resolve that pattern to a list of files.

func (Path) Info

func (p Path) Info() os.FileInfo

Info returns the file information for ths path.

func (Path) IsDir

func (p Path) IsDir() bool

IsDir returns true if the path exists and is a directory.

func (Path) IsEmpty

func (p Path) IsEmpty() bool

IsEmpty returns true if the path has no value.

func (Path) IsExecutable

func (p Path) IsExecutable() bool

IsExecutable returns true if the file at p.value exists, is executable and is not a directory.

func (Path) Join

func (p Path) Join(join ...string) Path

Join returns a path formed from joining this base with a child path. If there are any / characters in the strings, they will be converted to they system separator.

func (Path) MarshalJSON

func (p Path) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling to write paths as simple JSON strings.

func (Path) Matches

func (p Path) Matches(patterns ...string) bool

Matches returns true if the Path matches any of the patterns.

func (Path) NoExt

func (p Path) NoExt() Path

NoExt returns the path excluding the file extension or '.'.

func (Path) Parent

func (p Path) Parent() Path

Parent returns the parent directory of the path, if it has one. It will return the canonical version of the path if it is a root.

func (Path) RelativeTo

func (p Path) RelativeTo(base Path) (string, error)

RelativeTo returns the path of this File relative to base.

func (*Path) Set

func (p *Path) Set(value string) error

Set assigns the value of the path. This conforms to the flag variable interface.

func (Path) Slash

func (p Path) Slash() string

Slash returns the full absolute path using the / separator.

func (Path) Smash

func (p Path) Smash() (Path, string, string)

Smash returns the parent, name and extension of a path.

func (Path) Split

func (p Path) Split() (Path, string)

Split returns the parent and name of the path.

func (Path) SplitExt

func (p Path) SplitExt() (Path, string)

SplitExt returns the path excluding the file extension and the file extension. The extension includes the '.'.

func (Path) String

func (p Path) String() string

The default string form uses the system representation.

func (Path) System

func (p Path) System() string

System returns the full absolute path using the system separator.

func (Path) Timestamp

func (p Path) Timestamp() time.Time

Timestamp returns the last modified time reported by the file system.

func (Path) URL

func (p Path) URL() *url.URL

URL returns the full absolute path using the / separator prefixed by the URL file scheme.

func (*Path) UnmarshalJSON

func (p *Path) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling to read strings a paths.

func (Path) Walk

func (p Path) Walk(walkFn func(path Path, err error) error) error

Walk walks path.

type PathList

type PathList []Path

PathList is a list of file paths.

func Paths

func Paths(files ...Path) PathList

Paths returns a PathList formed from the list of paths.

func SplitList

func SplitList(paths string) PathList

SplitList splits a string on the system path list separator, and then resolves each produced string to a Path, returning the paths produced as a PathList.

func (PathList) Append

func (l PathList) Append(paths ...Path) PathList

Append is analogous to the append function.

func (PathList) AsSet

func (l PathList) AsSet() PathSet

AsSet returns the contents of the PathList as a PathSet.

func (PathList) Contains

func (l PathList) Contains(path Path) bool

Contains tests to see if the list contains the path.

func (PathList) Find

func (l PathList) Find(fragment string) Rooted

Find searches the paths in the list for on that when joined with the path fragment produces an existing file name.

func (PathList) Len

func (l PathList) Len() int

Len is the number of elements in the collection, so PathList implements sort.Interface.

func (PathList) Less

func (l PathList) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j, so PathList implements sort.Interface.

func (PathList) Matching

func (l PathList) Matching(patterns ...string) PathList

Matching returns the list of files that matches any supplied pattern.

func (PathList) NotMatching

func (l PathList) NotMatching(patterns ...string) PathList

NotMatching returns the list of files that does not match any supplied pattern.

func (PathList) RootOf

func (l PathList) RootOf(p Path) Rooted

RootOf returns the first Path that contains the path, or an empty path if not found.

func (*PathList) Set

func (l *PathList) Set(value string) error

func (PathList) String

func (l PathList) String() string

func (PathList) Swap

func (l PathList) Swap(i, j int)

Swap swaps the elements with indexes i and j, so PathList implements sort.Interface.

type PathSet

type PathSet struct {
	// contains filtered or unexported fields
}

PathSet is a list of file paths that does not allow duplicates.

func (PathSet) Append

func (s PathSet) Append(paths ...Path) PathSet

Append is analogous to the append function, except it also suppresses duplicates. It copies the set and then adds the supplied paths.

func (PathSet) AsList

func (s PathSet) AsList() PathList

AsList returns the contents of the PathSet as a List.

func (PathSet) Contains

func (s PathSet) Contains(path Path) bool

Contains tests to see if the set contains the path.

func (PathSet) Matching

func (s PathSet) Matching(patterns ...string) PathSet

Matching returns the set of paths that match any pattern.

func (PathSet) NotMatching

func (s PathSet) NotMatching(patterns ...string) PathSet

NotMatching returns the set of paths that do not match any pattern.

func (PathSet) RootOf

func (s PathSet) RootOf(p Path) Rooted

RootOf returns the first Path that contains the path, or an empty path if not found.

func (PathSet) Union

func (s PathSet) Union(other PathSet) PathSet

Union produces the union of this path set with another.

type Rooted

type Rooted struct {
	Root     Path
	Fragment string
}

Rooted is the type for a root path and fragment that when joined together form a full path. The fragment must not be an absolute path.

func Join

func Join(root Path, fragment string) Rooted

Join returns a Rooted path from the root and fragment supplied.

func (Rooted) Path

func (r Rooted) Path() Path

Path joins the root and fragment together into a normal absolute path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL