fs

package
v1.74.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MPL-2.0 Imports: 16 Imported by: 16

Documentation

Overview

Package fs provides filesystem-related utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseName

func BaseName(path string) string

BaseName returns the file name without the directory or extension.

func Copy added in v1.1.0

func Copy(src, dst string) error

Copy src to dst. src may be a directory, file, or symlink.

func CopyWithMask added in v1.40.0

func CopyWithMask(src, dst string, mask fs.FileMode) error

CopyWithMask src to dst. src may be a directory, file, or symlink.

func CreateTemp added in v1.74.0

func CreateTemp(dir, pattern string, perm os.FileMode) (*os.File, error)

CreateTemp is essentially the same as os.CreateTemp, except it allows you to specify the file mode of the newly created file.

func FileExists

func FileExists(path string) bool

FileExists returns true if the path points to a regular file.

func FileIsReadable added in v1.57.0

func FileIsReadable(path string) bool

FileIsReadable returns true if the path points to a regular file that we have permission to read.

func IsDir

func IsDir(path string) bool

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

func LoadJSON

func LoadJSON(path string, data any) error

LoadJSON data from the specified path.

func LoadJSONFromFS added in v1.50.0

func LoadJSONFromFS(fsys fs.FS, path string, data any) error

LoadJSONFromFS data from the specified filesystem path.

func LoadYAML

func LoadYAML(path string, data any) error

LoadYAML data from the specified path.

func LoadYAMLFromFS added in v1.50.0

func LoadYAMLFromFS(fsys fs.FS, path string, data any) error

LoadYAMLFromFS data from the specified filesystem path.

func MoveFile

func MoveFile(src, dst string) (err error)

MoveFile moves a file in the file system or across volumes, using rename if possible, but falling back to copying the file if not. This will error if either src or dst are not regular files.

func SanitizeName

func SanitizeName(name string) string

SanitizeName sanitizes a file name by replacing invalid characters.

func SaveJSON

func SaveJSON(path string, data any, format bool) error

SaveJSON data to the specified path.

func SaveJSONWithMode added in v1.40.0

func SaveJSONWithMode(path string, data any, format bool, mode os.FileMode) error

SaveJSONWithMode data to the specified path.

func SaveYAML

func SaveYAML(path string, data any) error

SaveYAML data to the specified path.

func SaveYAMLWithMode added in v1.40.0

func SaveYAMLWithMode(path string, data any, mode os.FileMode) error

SaveYAMLWithMode data to the specified path.

func Split

func Split(path string) []string

Split a path into its component parts. In the case of a full path, the first element will be filepath.Separator, possibly prefixed by a volume name. In the case of a relative path, the first element will be ".".

func TrimExtension

func TrimExtension(path string) string

TrimExtension trims any extension from the path.

func UniquePaths added in v1.26.0

func UniquePaths(paths ...string) ([]string, error)

UniquePaths returns a list of unique paths from the given paths, pruning out paths that are a subset of another.

func UnsanitizeName

func UnsanitizeName(name string) string

UnsanitizeName reverses the effects of a call to SanitizeName.

func Walk

func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error

Walk performs the same function as filepath.Walk() does, but works on http.FileSystem objects.

Types

This section is empty.

Directories

Path Synopsis
Package paths provides platform-specific standard paths.
Package paths provides platform-specific standard paths.
Package safe provides safe, atomic saving of files.
Package safe provides safe, atomic saving of files.
Package tar provides simple tar extraction.
Package tar provides simple tar extraction.
Package zip provides simple zip extraction.
Package zip provides simple zip extraction.

Jump to

Keyboard shortcuts

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