files

package
v1.0.88 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultDirWritePermissions default permissions when creating a directory
	DefaultDirWritePermissions = 0760

	// DefaultFileWritePermissions default permissions when creating a file
	DefaultFileWritePermissions = 0644

	MaximumNewDirectoryAttempts = 1000
)

Variables

This section is empty.

Functions

func ContentTypeForFileName

func ContentTypeForFileName(name string) string

ContentTypeForFileName returns the MIME type for the given file name

func CopyDirOverwrite

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

CopyDirOverwrite copies from the source dir to the destination dir overwriting files along the way

func CopyDirPreserve

func CopyDirPreserve(src string, dst string) error

CopyDirPreserve copies from the src dir to the dst dir if the file does NOT already exist in dst

func CopyFileOrDir

func CopyFileOrDir(src string, dst string, force bool) (err error)

CopyFileOrDir copies the source file or directory to the given destination

func CreateUniqueDirectory

func CreateUniqueDirectory(dir string, name string, maximumAttempts int) (string, error)

CreateUniqueDirectory creates a new directory but if the combination of dir and name exists then append a number until a unique name is found

func DeleteDirContents

func DeleteDirContents(dir string) error

DeleteDirContents removes all the contents of the given directory

func DeleteDirContentsExcept

func DeleteDirContentsExcept(dir string, exceptDir string) error

func DeleteFile

func DeleteFile(fileName string) (err error)

DeleteFile deletes a file from the operating system. This should NOT be used to delete any sensitive information because it can easily be recovered. Use DestroyFile to delete sensitive information

func DestroyFile

func DestroyFile(filename string) error

DestroyFile will securely delete a file by first overwriting it with random bytes, then deleting it. This should always be used for deleting sensitive information

func DirExists

func DirExists(path string) (bool, error)

DirExists checks if path exists and is a directory

func FileExists

func FileExists(path string) (bool, error)

FileExists checks if path exists and is a file

func FileIsEmpty

func FileIsEmpty(path string) (bool, error)

FileIsEmpty checks if a file is empty

func FilterFileExists

func FilterFileExists(paths []string) []string

FilterFileExists filters out files which do not exist

func FirstFileExists

func FirstFileExists(paths ...string) (string, error)

FirstFileExists returns the first file which exists or an error if we can't detect if a file that exists

func GlobAllFiles

func GlobAllFiles(basedir string, pattern string, fn func(string) error) error

GlobAllFiles performs a glob on the pattern and then processes all the files found. if a folder matches the glob its treated as another glob to recurse into the directory

func IgnoreFile

func IgnoreFile(path string, ignores []string) (bool, error)

IgnoreFile returns true if the path matches any of the ignores. The match is the same as filepath.Match.

func IsEmpty

func IsEmpty(name string) (bool, error)

func ListDirectory

func ListDirectory(root string, recurse bool) error

ListDirectory logs the directory at path

func LoadBytes

func LoadBytes(dir, name string) ([]byte, error)

loads a file

func RecreateDirs

func RecreateDirs(dirs ...string) error

DeleteDirContents removes all the contents of the given directory

func RecreateSymLink(src, target string) error

RecreateSymLink removes any old symlink/binary if they exist and creates a new symlink from the given source

func RenameDir

func RenameDir(src string, dst string, force bool) (err error)

func RenameFile

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

func ToValidFileSystemName

func ToValidFileSystemName(name string) string

ToValidFileSystemName converts the name to one that can safely be used on the filesystem

func UnTarFile

func UnTarFile(header *tar.Header, target string, tarReader io.Reader) error

UnTarFile extracts one file from the tar, or creates a directory

func UnTargz

func UnTargz(tarball, target string, onlyFiles []string) error

untargz a tarball to a target, from http://blog.ralch.com/tutorial/golang-working-with-tar-and-gzipf

func UnTargzAll

func UnTargzAll(tarball, target string) error

untargz a tarball to a target including any folders inside the tarball http://blog.ralch.com/tutorial/golang-working-with-tar-and-gzipf

func Unzip

func Unzip(src, dest string) error

Unzips the archvie into the specified directory returns an error if a general issue occurred unzipping the archive

func UnzipSpecificFiles

func UnzipSpecificFiles(src, dest string, onlyFiles ...string) error

Unzips the specified files from the archive returns an error if any of the specified files are not found or a general issue occurred unzipping the archive

Types

type IOFileHandles

type IOFileHandles struct {
	Err io.Writer
	In  terminal.FileReader
	Out terminal.FileWriter
}

IOFileHandles is a struct for holding CommonOptions' In, Out, and Err I/O handles, to simplify function calls.

func GetIOFileHandles

func GetIOFileHandles(h *IOFileHandles) IOFileHandles

GetIOFileHandles lazily creates a file handles object if the input is nil

Jump to

Keyboard shortcuts

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