Documentation ¶
Overview ¶
Package fs contains helper functions to deal with files and folders.
Index ¶
- Variables
- func AbsoluteFileExists(path string) (res bool)
- func ApplyCommands(cmds []*exec.Cmd, title string, verbose bool) error
- func CalculateMD5(filename string) (string, error)
- func CalculateMD5First4KB(path string) string
- func CalculateSHA256(filename string) (string, error)
- func ContainsNonStandardSpace(s string) bool
- func CopyDir(src, dst string, useHardLinks bool) error
- func CopyFile(src, dst string, useHardLinks bool) (err error)
- func DeleteEmptyDirs(root string, whitelist []string) error
- func DirExists(path string) bool
- func DirIsEmpty(path string) (bool, error)
- func DownloadFile(filepath string, url string) error
- func FileExists(path string) bool
- func FileSize(a uint64) string
- func FileSizeDelta(a int64) string
- func GetAllowedFilesByExt(directoryPath string, extensionWhitelist []string) []string
- func GetExceedinglyLongPaths(dir string, maxSize int) []string
- func GetFilesAndFoldersByPrefix(directoryPath string, prefixWhitelist []string) []string
- func GetFilesAndFoldersBySubstring(directoryPath string, prefixWhitelist []string) []string
- func GetFilesByExt(directoryPath, extension string) ([]string, error)
- func GetForbiddenFilesByExt(directoryPath string, extensionWhitelist []string) []string
- func GetMaxPathLength(dir string) int
- func GetPartialSize(directoryPath string, whitelisted []string) int
- func GetPathsWithNonStandardSpaces(dir string) []string
- func GetTopLevelSubDirectories(root string) ([]string, error)
- func GetTotalSize(directoryPath string) int
- func GetUniqueFolder(basePath string) (string, error)
- func GetUniqueTimestampedFilename(dir, filename, extension string) (string, error)
- func HasEmptyNestedFolders(dir string) bool
- func MoveDir(current, new string, doNothing, interactive bool) (bool, error)
- func ResizeJPGIfNecessary(image string, maxSizeKb int) (string, bool, error)
- func SanitizePath(path string) string
- func Sign(a int64) string
- type ByteSize
Constants ¶
This section is empty.
Variables ¶
var UnicodeNonStandardSpaces = []string{"\u00a0", "\u1680", "\u180e", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200a", "\u200b", "\u200c", "\u200d", "\u200e", "\u200f", "\u2063", "\u2028", "\u2029", "\u202a", "\u202b", "\u202c", "\u202d", "\u202e", "\u202f", "\u205f", "\u2060", "\u2061", "\u2062", "\u2063", "\u2064", "\u3000", "\ufeff"}
Functions ¶
func AbsoluteFileExists ¶
AbsoluteFileExists checks if an absolute path is an existing file.
func ApplyCommands ¶ added in v0.16.0
ApplyCommands using goroutines. Can be applied to files.
func CalculateMD5 ¶ added in v0.23.0
CalculateMD5 calculates a file's current md5 hash.
func CalculateMD5First4KB ¶
CalculateMD5First4KB calculates the MD5 of the beginning of a file.
func CalculateSHA256 ¶
CalculateSHA256 calculates a file's current sh&256 hash.
func ContainsNonStandardSpace ¶ added in v0.42.0
func CopyDir ¶
CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped.
func CopyFile ¶
CopyFile copies a fs from src to dst. If src and dst files exist, and are the same, then return success. Copy the fs contents from src to dst.
func DeleteEmptyDirs ¶
DeleteEmptyDirs recursively deletes empty folders in a given path.
func DirIsEmpty ¶
DirIsEmpty checks if a directory is empty.
func DownloadFile ¶
DownloadFile will download a url to a local file. It will write as it downloads and not load the whole file into memory.
func FileSizeDelta ¶
func GetAllowedFilesByExt ¶ added in v0.25.0
GetAllowedFilesByExt returns all files found in a directory with an extension that is whitelisted.
func GetExceedinglyLongPaths ¶ added in v0.19.7
GetExceedinglyLongPaths returns paths longer that maxSize inside of a root directory.
func GetFilesAndFoldersByPrefix ¶ added in v0.25.0
GetFilesAndFoldersByPrefix returns all files and folders found in a directory with specific prefixes.
func GetFilesAndFoldersBySubstring ¶ added in v0.25.0
GetFilesAndFoldersBySubstring returns all files and folders found in a directory with specific substrings.
func GetFilesByExt ¶ added in v0.3.0
GetFilesByExt returns all files found in a directory with a specific extension.
func GetForbiddenFilesByExt ¶ added in v0.25.0
GetForbiddenFilesByExt returns all files found in a directory with an extension that isn't whitelisted.
func GetMaxPathLength ¶ added in v0.17.0
GetMaxPathLength inside a directory, including the name of the directory itself.
func GetPartialSize ¶ added in v0.25.0
GetPartialSize returns the size of some of the contents in a folder.
func GetPathsWithNonStandardSpaces ¶ added in v0.42.0
func GetTopLevelSubDirectories ¶ added in v0.30.0
func GetTotalSize ¶ added in v0.25.0
GetTotalSize returns the size of a folder.
func GetUniqueFolder ¶ added in v0.20.0
GetUniqueFolder in a target directory, append indices if folder already exists.
func GetUniqueTimestampedFilename ¶
GetUniqueTimestampedFilename for a given filename.
func HasEmptyNestedFolders ¶ added in v0.25.0
GetEmptyNestedFolders returns true if it contains empty dirs, or dirs that only contain other dirs.
func ResizeJPGIfNecessary ¶ added in v0.23.0
ResizeJPGIfNecessary and return the path to the acceptable image, and whether it is the original or a resized version.