fs

package
Version: v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT Imports: 21 Imported by: 9

Documentation

Overview

Package fs contains helper functions to deal with files and folders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsoluteFileExists

func AbsoluteFileExists(path string) (res bool)

AbsoluteFileExists checks if an absolute path is an existing file.

func ApplyCommands added in v0.16.0

func ApplyCommands(cmds []*exec.Cmd, title string, verbose bool) error

ApplyCommands using goroutines. Can be applied to files.

func CalculateMD5 added in v0.23.0

func CalculateMD5(filename string) (string, error)

CalculateMD5 calculates a file's current md5 hash.

func CalculateMD5First4KB

func CalculateMD5First4KB(path string) string

CalculateMD5First4KB calculates the MD5 of the beginning of a file.

func CalculateSHA256

func CalculateSHA256(filename string) (string, error)

CalculateSHA256 calculates a file's current sh&256 hash.

func CopyDir

func CopyDir(src, dst string, useHardLinks bool) error

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

func CopyFile(src, dst string, useHardLinks bool) (err error)

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

func DeleteEmptyDirs(root string, whitelist []string) error

DeleteEmptyDirs recursively deletes empty folders in a given path.

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists.

func DirIsEmpty

func DirIsEmpty(path string) (bool, error)

DirIsEmpty checks if a directory is empty.

func DownloadFile

func DownloadFile(filepath string, url string) error

DownloadFile will download a url to a local file. It will write as it downloads and not load the whole file into memory.

func FileExists

func FileExists(path string) bool

FileExists checks if a path is valid.

func FileSize

func FileSize(a uint64) string

func FileSizeDelta

func FileSizeDelta(a int64) string

func GetAllowedFilesByExt added in v0.25.0

func GetAllowedFilesByExt(directoryPath string, extensionWhitelist []string) []string

GetAllowedFilesByExt returns all files found in a directory with an extension that is whitelisted.

func GetExceedinglyLongPaths added in v0.19.7

func GetExceedinglyLongPaths(dir string, maxSize int) []string

GetExceedinglyLongPaths returns paths longer that maxSize inside of a root directory.

func GetFilesAndFoldersByPrefix added in v0.25.0

func GetFilesAndFoldersByPrefix(directoryPath string, prefixWhitelist []string) []string

GetFilesAndFoldersByPrefix returns all files and folders found in a directory with specific prefixes.

func GetFilesAndFoldersBySubstring added in v0.25.0

func GetFilesAndFoldersBySubstring(directoryPath string, prefixWhitelist []string) []string

GetFilesAndFoldersBySubstring returns all files and folders found in a directory with specific substrings.

func GetFilesByExt added in v0.3.0

func GetFilesByExt(directoryPath, extension string) ([]string, error)

GetFilesByExt returns all files found in a directory with a specific extension.

func GetForbiddenFilesByExt added in v0.25.0

func GetForbiddenFilesByExt(directoryPath string, extensionWhitelist []string) []string

GetForbiddenFilesByExt returns all files found in a directory with an extension that isn't whitelisted.

func GetMaxPathLength added in v0.17.0

func GetMaxPathLength(dir string) int

GetMaxPathLength inside a directory, including the name of the directory itself.

func GetPartialSize added in v0.25.0

func GetPartialSize(directoryPath string, whitelisted []string) int

GetPartialSize returns the size of some of the contents in a folder.

func GetTopLevelSubDirectories added in v0.30.0

func GetTopLevelSubDirectories(root string) ([]string, error)

func GetTotalSize added in v0.25.0

func GetTotalSize(directoryPath string) int

GetTotalSize returns the size of a folder.

func GetUniqueFolder added in v0.20.0

func GetUniqueFolder(basePath string) (string, error)

GetUniqueFolder in a target directory, append indices if folder already exists.

func GetUniqueTimestampedFilename

func GetUniqueTimestampedFilename(dir, filename, extension string) (string, error)

GetUniqueTimestampedFilename for a given filename.

func HasEmptyNestedFolders added in v0.25.0

func HasEmptyNestedFolders(dir string) bool

GetEmptyNestedFolders returns true if it contains empty dirs, or dirs that only contain other dirs.

func MoveDir added in v0.5.0

func MoveDir(current, new string, doNothing, interactive bool) (bool, error)

MoveDir moves a directory to its new home.

func ResizeJPGIfNecessary added in v0.23.0

func ResizeJPGIfNecessary(image string, maxSizeKb int) (string, bool, error)

ResizeJPGIfNecessary and return the path to the acceptable image, and whether it is the original or a resized version.

func SanitizePath

func SanitizePath(path string) string

SanitizePath to have an acceptable path.

func Sign added in v0.2.0

func Sign(a int64) string

Types

type ByteSize

type ByteSize float64
const (
	KiB ByteSize = 1 << (10 * iota)
	MiB
	GiB
	TiB
)

func (ByteSize) String

func (b ByteSize) String() string

Jump to

Keyboard shortcuts

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