fileutils

package
v0.0.0-...-c4d1043 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(pth string) (string, error)

AbsPath expands ENV vars and the ~ character

then call Go's Abs

func AppendBytesToFile

func AppendBytesToFile(pth string, fileCont []byte) error

AppendBytesToFile ...

func AppendStringToFile

func AppendStringToFile(pth string, fileCont string) error

AppendStringToFile ...

func ChangeDirForFunction

func ChangeDirForFunction(dir string, fn func()) error

ChangeDirForFunction ...

func CopyDir

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

CopyDir ...

func CopyFile

func CopyFile(src, dst string) error

CopyFile ...

func CurrentWorkingDirectoryAbsolutePath

func CurrentWorkingDirectoryAbsolutePath() (string, error)

CurrentWorkingDirectoryAbsolutePath ...

func DownloadAndUnZIP

func DownloadAndUnZIP(url, pth string) error

DownloadAndUnZIP ...

func EnsureDirExist

func EnsureDirExist(dir string) error

EnsureDirExist ...

func ExpandTilde

func ExpandTilde(pth string) (string, error)

ExpandTilde ...

func GetFileModeOfFile

func GetFileModeOfFile(pth string) (os.FileMode, error)

GetFileModeOfFile ...

this is the "permissions" info, which can be passed directly to
functions like WriteBytesToFileWithPermission or os.OpenFile

func GetFileName

func GetFileName(path string) string

GetFileName returns the name of the file from a given path or the name of the directory if it is a directory

func GetFilePermissions

func GetFilePermissions(filePth string) (os.FileMode, error)

GetFilePermissions ...

  • alias of: GetFileModeOfFile this is the "permissions" info, which can be passed directly to functions like WriteBytesToFileWithPermission or os.OpenFile

func IsDirExists

func IsDirExists(pth string) (bool, error)

IsDirExists ...

func IsPathExists

func IsPathExists(pth string) (bool, error)

IsPathExists ...

func IsRelativePath

func IsRelativePath(pth string) bool

IsRelativePath ...

func NormalizedOSTempDirPath

func NormalizedOSTempDirPath(tmpDirNamePrefix string) (retPth string, err error)

NormalizedOSTempDirPath ... Creates a temp dir, and returns its path. If tmpDirNamePrefix is provided it'll be used

as the tmp dir's name prefix.

Normalized: it's guaranteed that the path won't end with '/'.

func PathCheckAndInfos

func PathCheckAndInfos(pth string) (os.FileInfo, bool, error)

PathCheckAndInfos ... Returns: 1. file info or nil 2. bool, indicating whether the path exists 3. error, if any error happens during the check

func ReadBytesFromFile

func ReadBytesFromFile(pth string) ([]byte, error)

ReadBytesFromFile ...

func ReadFileInto

func ReadFileInto(filename string, v proto.Message) error

func ReadLongLine

func ReadLongLine(r *bufio.Reader) (string, error)

ReadLongLine - an alternative to bufio.Scanner.Scan, which can't handle long lines. This function is slower than bufio.Scanner.Scan, but can handle arbitrary long lines.

func ReadStringFromFile

func ReadStringFromFile(pth string) (string, error)

ReadStringFromFile ...

func RemoveAll

func RemoveAll(pths ...string) error

RemoveAll removes recursively every file on the given paths.

func RemoveDir

func RemoveDir(dirPth string) error

RemoveDir ... Deprecated: use RemoveAll instead.

func RemoveFile

func RemoveFile(pth string) error

RemoveFile ... Deprecated: use RemoveAll instead.

func RetrieveArchive

func RetrieveArchive(fs afero.Fs, uri string) (io.ReadCloser, error)

Retrieves the file from the given uri The uri can be a remote url or a file on the local fs This function returns a ReadCloser and it is the responsibility of the caller to close it

func RevokableChangeDir

func RevokableChangeDir(dir string) (func() error, error)

RevokableChangeDir ...

func Tar

func Tar(src string, fs afero.Fs, writers ...io.Writer) error

func UnZIP

func UnZIP(src, dest string) error

UnZIP ...

func UnZip

func UnZip(zip, intoDir string) error

UnZip ...

func Untar

func Untar(dst, src string, fs afero.Fs) error

func UserHomeDir

func UserHomeDir() string

UserHomeDir ...

func WalkLines

func WalkLines(inpReader io.Reader, walkFn WalkLineFn) error

WalkLines ...

func WalkLinesString

func WalkLinesString(inputStr string, walkFn WalkLineFn) error

WalkLinesString ...

func WriteBytesToFile

func WriteBytesToFile(pth string, fileCont []byte) error

WriteBytesToFile ...

func WriteBytesToFileWithPermission

func WriteBytesToFileWithPermission(pth string, fileCont []byte, perm os.FileMode) error

WriteBytesToFileWithPermission ...

func WriteStringToFile

func WriteStringToFile(pth string, fileCont string) error

WriteStringToFile ...

func WriteStringToFileWithPermission

func WriteStringToFileWithPermission(pth string, fileCont string, perm os.FileMode) error

WriteStringToFileWithPermission ...

func WriteToFile

func WriteToFile(filename string, pb proto.Message) error

func ZipDir

func ZipDir(sourceDirPth, destinationZipPth string, isContentOnly bool) error

ZipDir ...

func ZipFile

func ZipFile(sourceFilePth, destinationZipPth string) error

ZipFile ...

Types

type WalkLineFn

type WalkLineFn func(string) error

WalkLineFn - gets a line as its input if returns an error it stops the walk/reading to break the walk early, without an error, just return io.EOF

Jump to

Keyboard shortcuts

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