io

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 56

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 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 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 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 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 IsFileSymlink(file os.FileInfo) bool
func IsPathSymlink(path string) bool

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 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