io

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 22 Imported by: 61

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShortWrite = errors.New("the number of bytes written is less than the length of the input")
View Source
var ErrSkipDir = errors.New("skip this directory")

Functions

func AsyncMultiWriter added in v1.7.0

func AsyncMultiWriter(limit int, writers ...io.Writer) io.Writer

AsyncMultiWriter creates a writer that duplicates its writes to all the provided writers asynchronous

func CleanOldDirs added in v1.7.3

func CleanOldDirs() error

Old runs/tests may leave junk at temp dir. Each temp file/Dir is named with prefix+timestamp, search for all temp files/dirs that match the common prefix and validate their timestamp.

func Close added in v1.6.2

func Close(closer io.Closer, err *error)

Close the reader/writer and append the error to the given error.

func CopyDir added in v1.7.3

func CopyDir(fromPath, toPath string, includeDirs bool, excludeNames []string) error

Copy directory content from one path to another. includeDirs means to copy also the dirs if presented in the src folder. excludeNames - Skip files/dirs in the src folder that match names in provided slice. ONLY excludes first layer (only in src folder).

func CopyFile added in v1.7.3

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

func CreateDirIfNotExist added in v1.7.3

func CreateDirIfNotExist(path string) error

func CreateFilePath added in v1.7.3

func CreateFilePath(localPath, fileName string) (string, error)

func CreateRandomLenFile

func CreateRandomLenFile(maxLen int, filesDir string, prefix string) string

Create a temp file with the requested prefix at the provided dir. File length and contents are random, up to the requested max length.

func CreateTempDir added in v1.7.3

func CreateTempDir() (string, error)

CreateTempDir creates a temporary directory and returns its path.

func DoubleWinPathSeparator added in v1.7.3

func DoubleWinPathSeparator(filePath string) string

func DownloadFile added in v1.7.3

func DownloadFile(downloadTo string, fromUrl string) (err error)

func FindFileInDirAndParents added in v1.7.3

func FindFileInDirAndParents(dirPath, fileName string) (string, error)

FindFileInDirAndParents looks for a file named fileName in dirPath and its parents, and returns the path of the directory where it was found. dirPath must be a full path.

func GetFileAndDirFromPath added in v1.7.3

func GetFileAndDirFromPath(path string) (fileName, dir string)

Return the file's name and dir of a given path by finding the index of the last separator in the path. Support separators : "/" , "\\" and "\\\\"

func GetFileContentAndInfo added in v1.7.3

func GetFileContentAndInfo(filePath string) (fileContent []byte, fileInfo os.FileInfo, err error)

func GetFileInfo added in v1.1.2

func GetFileInfo(path string, followSymlink bool) (fileInfo os.FileInfo, err error)

Get the file info of the file in path. If path points at a symlink and `followSymlink == false`, return the file info of the symlink instead

func GetFileSeparator added in v1.7.3

func GetFileSeparator() string

func IsDirExists added in v1.1.2

func IsDirExists(path string, followSymlink bool) (bool, error)

Check if path points at a directory. If path points at a symlink and `followSymlink == false`, function will return `false` regardless of the symlink target

func IsFileExists added in v1.7.3

func IsFileExists(path string, followSymlink bool) (bool, error)

Checxk if path points at a file. If path points at a symlink and `followSymlink == false`, function will return `true` regardless of the symlink target

func IsFileSymlink(file os.FileInfo) bool

func IsPathExists added in v1.7.3

func IsPathExists(path string) bool

IsPathExists checks if a path exists.

func IsPathSymlink(path string) bool

func ListFiles added in v1.7.3

func ListFiles(path string, includeDirs bool) ([]string, error)

Return the list of files and directories in the specified path

func ListFilesByFilterFunc added in v1.7.3

func ListFilesByFilterFunc(path string, filterFunc func(filePath string) (bool, error)) ([]string, error)

Return all files in the specified path who satisfy the filter func. Not recursive.

func MoveDir added in v1.7.3

func MoveDir(fromPath, toPath string) error

Move directory content from one path to another.

func MoveFile added in v1.7.3

func MoveFile(sourcePath, destPath string) (err error)

GoLang: os.Rename() give error "invalid cross-device link" for Docker container with Volumes. MoveFile(source, destination) will work moving file between folders Therefore, we are using our own implementation (MoveFile) in order to rename files.

func ReadNLines added in v1.7.3

func ReadNLines(path string, total int) (lines []string, err error)

strip '\n' or read until EOF, return error if read error readNLines reads up to 'total' number of lines separated by \n.

func RemoveTempDir added in v1.7.3

func RemoveTempDir(dirPath string) error

func RunCmd added in v1.0.3

func RunCmd(config CmdConfig) error

Runs an external process and prints its output to stdout / stderr.

func RunCmdOutput added in v1.0.3

func RunCmdOutput(config CmdConfig) (string, error)

Executes an external process and returns its output. If the returned output is not needed, use the RunCmd function instead , for better performance.

func RunCmdWithOutputParser added in v1.0.3

func RunCmdWithOutputParser(config CmdConfig, prompt bool, regExpStruct ...*CmdOutputPattern) (stdOut string, errorOut string, exitOk bool, err error)

Executes the command and captures the output. Analyze each line to match the provided regex. Returns the complete stdout output of the command.

func Unmarshal added in v1.7.3

func Unmarshal(filePath string, loadTarget interface{}) (err error)

Parses the JSON-encoded data and stores the result in the value pointed to by 'loadTarget'. filePath - Path to json file. loadTarget - Pointer to a struct

func Walk added in v1.1.2

func Walk(root string, walkFn WalkFunc, walkIntoDirSymlink bool) error

The same as filepath.Walk the only difference is that we can walk into symlink. Avoiding infinite loops by saving the real paths we already visited.

Types

type CmdConfig added in v1.0.3

type CmdConfig interface {
	GetCmd() *exec.Cmd
	GetEnv() map[string]string
	GetStdWriter() io.WriteCloser
	GetErrWriter() io.WriteCloser
}

type CmdOutputPattern added in v1.0.3

type CmdOutputPattern struct {
	RegExp         *regexp.Regexp
	MatchedResults []string
	Line           string
	ExecFunc       func(pattern *CmdOutputPattern) (string, error)
}

RegExp - The regexp that the line will be searched upon. MatchedResults - The slice result that was found by the regexp Line - The output line from the external process ExecFunc - The function to execute

type Command added in v1.3.2

type Command struct {
	Executable string
	CmdName    string
	CmdArgs    []string
	Dir        string
	StrWriter  io.WriteCloser
	ErrWriter  io.WriteCloser
}

func NewCommand added in v1.3.2

func NewCommand(executable, cmdName string, cmdArgs []string) *Command

func (*Command) GetCmd added in v1.3.2

func (config *Command) GetCmd() (cmd *exec.Cmd)

func (*Command) GetEnv added in v1.3.2

func (config *Command) GetEnv() map[string]string

func (*Command) GetErrWriter added in v1.3.2

func (config *Command) GetErrWriter() io.WriteCloser

func (*Command) GetStdWriter added in v1.3.2

func (config *Command) GetStdWriter() io.WriteCloser

func (*Command) RunWithOutput added in v1.3.2

func (config *Command) RunWithOutput() (data []byte, err error)

type RandFile

type RandFile struct {
	*os.File
	Info os.FileInfo
}

func CreateRandFile

func CreateRandFile(path string, len int) (file *RandFile, err error)

Create a file at the provided path with a request number of random bytes.

type Stat added in v1.1.2

type Stat func(path string) (info os.FileInfo, err error)

type WalkFunc added in v1.1.2

type WalkFunc func(path string, info os.FileInfo, err error) error

Jump to

Keyboard shortcuts

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