iohelper

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src string, dst string) (err 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) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.

func Pipe

func Pipe() (io.ReadCloser, io.WriteCloser)

Pipe returns io.Pipe if os.Pipe errored

func TempFilename added in v0.2.0

func TempFilename(dir, pattern string) (string, error)

func WriteFile

func WriteFile(file string, data []byte, perm os.FileMode, overwrite bool) (undo func() error, _ error)

WriteFile write data to target file

Types

type TimeoutReader

type TimeoutReader struct {
	// contains filtered or unexported fields
}

TimeoutReader is a reader with read timeout

It is designed for those want to read some data from a stream, and the size of the data is unknown, but still want to pipe data to some destination.

func NewTimeoutReader

func NewTimeoutReader(r io.Reader, chunkSize int) *TimeoutReader

NewTimeoutReader creates a new idle timeout reader

func (*TimeoutReader) Error

func (t *TimeoutReader) Error() error

Error returns the error happened during reading in background

func (*TimeoutReader) ReadUntilTimeout

func (t *TimeoutReader) ReadUntilTimeout(stop <-chan time.Time) (data []byte, isTimeout bool)

ReadUntilTimeout perform a read operation on buffered data, return a chunk of data if

the size of the buffered data has reached or maxed out the chunkSize, then the size of returned data chunk will be chunkSize

or

the stop signaled, but buffer is not full, will return all buffered data

func (*TimeoutReader) StartBackgroundReading

func (t *TimeoutReader) StartBackgroundReading()

StartBackgroundReading until EOF or error returned, should be called in a goroutine other than the one you are reading

func (*TimeoutReader) WaitUntilHasData

func (t *TimeoutReader) WaitUntilHasData(stopSig <-chan struct{}) bool

WaitUntilHasData is a helper function used to check if there is data available, to reduce actual call of ReadUntilTimeout when the timeout is a short duration

Jump to

Keyboard shortcuts

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