fs

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotDir  = errors.New("a file is located at the expected directory location")
	ErrDirNotFile  = errors.New("a directory is located at the expected file location")
	ErrDirNotExist = errors.New("directory does not exist")
	ErrDirNotEmpty = errors.New("directory is not empty")
)

Error Codes

Functions

func ByteSizeStr

func ByteSizeStr(sz uint64) string

func CheckDirExists

func CheckDirExists(path ...string) (bool, error)

func CheckFileExists

func CheckFileExists(path ...string) (bool, error)

func CheckFileHasContent

func CheckFileHasContent(fn string, buf []byte) bool

CheckFileHasContent returns true if the specified file exists and has content that matches buf.

func DirExists

func DirExists(path ...string) bool

DirExists returns true if a directory exists at the specified location. If the path points to a file, this function returns false.

func FileExists

func FileExists(path ...string) bool

FileExists returns true if a file exists at the specified location. If the path points to a directory, this function returns false.

func JSONErrDetail

func JSONErrDetail(input string, err error) error

JSONErrDetail ammends an error returned from json.Unmarshal with line:position info.

func JoinPathList added in v0.1.0

func JoinPathList(paths ...string) string

JoinPathList joins multiple paths into a string with OS-specific path separator. This is an opposite of the GOLANG's filepath.SplitList() function.

func LineAndCharacter

func LineAndCharacter(input string, offset int) (line int, character int, err error)

LineAndCharacter locates line and pos from offset into a file

func NormalizePathsToSlash added in v0.1.0

func NormalizePathsToSlash(paths []string) []string

NormalizePathsToSlash normalizes a list of file paths: - removes empty paths - converts separators to slashes - removes duplicates - sorts

func ReadJSON

func ReadJSON(fn string, v interface{}) error

func ResolvesToSameFile added in v0.1.0

func ResolvesToSameFile(pathA, pathB string) bool

ResolvesToSameFile returns true if the two paths resolve to the same actual file. Follows symlinks.

func SearchDir added in v0.1.0

func SearchDir(dir dirname, accept func(os.FileInfo) bool) []filename

SearchDir returns the list of paths within the specified directory that pass through the 'accept' callback. This is a non-recursive search.

func SearchFilesAndSymlinks(dirs []string, accept func(os.FileInfo) bool) map[filename][]symlink

SearchFilesAndSymlinks scans the provided set of directories and returns absolute filenames that pass through a functional 'accept' filter.

While searching, symlinks are resolved. For symlinks, the 'accept' is called twice: first on a symlink itself, then on its target.

Returns a map of real absolute file paths and symlinks pointing to those files.

func ValidateDirExists

func ValidateDirExists(path ...string) error

func ValidateEmptyDirExists

func ValidateEmptyDirExists(path ...string) error

func ValidateFileExists

func ValidateFileExists(path ...string) error

func WriteFileIfChanged

func WriteFileIfChanged(fn string, buf []byte) error

WriteFileIfChanged writes buf into a file. Does not overwrite if the file already has the specified content. Uses 0666 permission if overwriting is neccessary.

func WriteJSON

func WriteJSON(fn string, v interface{}) error

WriteJSON marshals v to JSON and writes it to the specified file with 0666 permissions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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