Documentation ¶
Overview ¶
Package iohlp contains small io-related utility functions.
Index ¶
- func ConcurrentReader(r io.Reader) io.Reader
- func Fcntl(fd uintptr, cmd, flags int) error
- func FindReader(r io.Reader, needle []byte) (int, error)
- func FindReaderSize(r io.Reader, needle []byte, bufSize int) (int, error)
- func MakeSectionReader(r io.Reader, threshold int) (*io.SectionReader, error)
- func MmapFile(fn string) (io.ReaderAt, error)
- func NewMultiCloser(c ...io.Closer) *multiCloser
- func NewStreamReplacer(r io.Reader, patternReplacementPairs ...[]byte) io.Reader
- func RedirFd(fd int) (*os.File, func() error, error)
- func SetDirect(f *os.File) error
- func Slurp(r io.Reader, threshold int) (data []byte, cleanup func(), err error)
- func URLEncode(w io.Writer, keyvals ...NamedReader) error
- func Walk(root string, walkFn filepath.WalkFunc) error
- func WalkWithSymlinks(root string, walkFn filepath.WalkFunc) error
- func WrappingReader(r io.Reader, width uint) io.Reader
- type BytesReplacer
- type CloserFunc
- type ErrWriter
- type HeadTailKeeper
- type NamedReader
- type ReaderAt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConcurrentReader ¶
ConcurrentReader wraps the given io.Reader such that it can be called concurrently.
func FindReader ¶ added in v0.18.2
FindReader finds the first occurrence of needle in the io.Reader and gives back its position. Returns -1 when needle is not found.
Uses the default buffer size (64kB).
func FindReaderSize ¶ added in v0.18.2
FindReaderSize finds the first occurrence of needle in the io.Reader and gives back its position. Returns -1 when needle is not found.
Uses the specified amount of buffer (must be longer than needle!).
func MakeSectionReader ¶
MakeSectionReader reads the reader and returns the byte slice.
If the read length is below the threshold, then the bytes are read into memory; otherwise, a temp file is created, and mmap-ed.
func NewMultiCloser ¶
NewMultiCloser returns an io.Closer which will close all contained io.Closer, in the given order.
func NewStreamReplacer ¶
NewStreamReplacer returns an io.Reader in which all non-overlapping patterns are replaced to their replacement pairs (such as a strings.Replacer on strings).
func RedirFd ¶
RedirFd redirects the fd, returns a reader pipe for the written data, and a cleanup function that reverses the effect of this function (closes the writer and redirects the fd).
func Slurp ¶ added in v0.26.4
Slurp reads the reader and returns the byte slice.
If the read length is below the threshold, then the bytes are read into memory; otherwise, a temp file is created, and mmap-ed.
func URLEncode ¶
func URLEncode(w io.Writer, keyvals ...NamedReader) error
URLEncode encodes the Name:Reader pairs just as url.Values.Encode does.
func Walk ¶
Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked UNORDERED, which makes the output undeterministic! Walk does not follow symbolic links.
func WalkWithSymlinks ¶
WalkWithSymlinks walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked UNORDERED, which makes the output undeterministic! WalkWithSymlinks does follow symbolic links!
Types ¶
type BytesReplacer ¶
type BytesReplacer [][2][]byte
BytesReplacer is a Replacer for bytes.
func NewBytesReplacer ¶
func NewBytesReplacer(patternReplacementPairs ...[]byte) BytesReplacer
NewBytesReplacer returns a Replacer, such as strings.Replacer, but for []byte.
func (BytesReplacer) MaxPatternLen ¶
func (br BytesReplacer) MaxPatternLen() int
func (BytesReplacer) Replace ¶
func (br BytesReplacer) Replace(p []byte) []byte
Replace as strings.Replacer would do.
type ErrWriter ¶
ErrWriter is a writer with a "stuck-in" error policy: writes normally, until the underlying io.Writer returns error; then after it always returns that error.
type HeadTailKeeper ¶ added in v0.27.3
type HeadTailKeeper struct { Limit int // contains filtered or unexported fields }
HeadTailKeeper is an io.Writer which keeps only Limit bytes from the start (head), and Limit bytes from the end (tail).
func (*HeadTailKeeper) Head ¶ added in v0.27.3
func (htw *HeadTailKeeper) Head() []byte
func (*HeadTailKeeper) Reset ¶ added in v0.27.3
func (htw *HeadTailKeeper) Reset()
func (*HeadTailKeeper) String ¶ added in v0.27.3
func (htw *HeadTailKeeper) String() string
func (*HeadTailKeeper) Sum64 ¶ added in v0.27.3
func (htw *HeadTailKeeper) Sum64() uint64
func (*HeadTailKeeper) Tail ¶ added in v0.27.3
func (htw *HeadTailKeeper) Tail() []byte
type NamedReader ¶
type ReaderAt ¶
type ReaderAt struct {
// contains filtered or unexported fields
}
ReaderAt reads a memory-mapped file.
Like any io.ReaderAt, clients can execute parallel ReadAt calls, but it is not safe to call Close and reading methods concurrently.
Copied from https://github.com/golang/exp/blob/85be41e4509f/mmap/mmap_unix.go#L115
func Mmap ¶
Mmap the file for read, return the bytes and the error. Will read the data directly if Mmap fails.