iox

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(closer io.Closer)

Close a resource, and ignore error. Useful for avoiding warning when use with defer: defer iox.Close(r)

func CloseAll

func CloseAll[T io.Closer](closers ...T)

CloseAll close multi closers and ignore errors

func EmptyReader

func EmptyReader() io.Reader

EmptyReader return an empty reader

func ForEachLine

func ForEachLine(r io.Reader, consume func(line string)) error

ForEachLine read all lines in reader, and call consume function, The line index pass to function start from 0. If and err occurred during read, return an error. If read all data succeed till and io.EOF, nil error will be returned.

func ForEachLineWithEncoding

func ForEachLineWithEncoding(r io.Reader, encoding encoding.Encoding, consume func(line string)) error

ForEachLineWithEncoding read all lines in reader with specific encoding, and call consume function, The line index pass to function start from 0. If and err occurred during read, return an error. If read all data succeed till and io.EOF, nil error will be returned.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll read and return all data in reader

func ReadAllLines

func ReadAllLines(r io.Reader) ([]string, error)

ReadAllLines read all data as string lines, till EOF, return a lines slice. The reader will be left unclosed

func ReadAllLinesWithEncoding

func ReadAllLinesWithEncoding(r io.Reader, enc encoding.Encoding) ([]string, error)

ReadAllLinesWithEncoding read all data as string line with specific encoding till EOF, return a lines slice. The reader will be left unclosed

func ReadAllString

func ReadAllString(r io.Reader) (string, error)

ReadAllString read and return all data as string in reader

func ReadAllStringWithEncoding

func ReadAllStringWithEncoding(r io.Reader, encoding encoding.Encoding) (string, error)

ReadAllStringWithEncoding read and return all data as string in reader, with encoding the data used

func TryClose

func TryClose(resource interface{})

TryClose close a resource, if the resource is an io.Closer. If close return an error, the error is ignored.

func TryCloseAll

func TryCloseAll[T any](resources ...T)

TryCloseAll try close multi resources, if it is a closer

Types

type LineReader

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

LineReader is a read which can read line by line, without limitation for line length.

func NewLineReader

func NewLineReader(r io.Reader) *LineReader

NewLineReader create new LineReader

func NewLineReaderSize

func NewLineReaderSize(r io.Reader, initialSize int) *LineReader

NewLineReaderSize create new LineReader with initial buf size

func (*LineReader) ForEachLine

func (r *LineReader) ForEachLine(consume func(line string)) error

ForEachLine read every line from the reader, and call consume function. If and err occurred during read, return an error. If read all data succeed till and io.EOF, nil error will be returned.

func (*LineReader) ReadAllLines

func (r *LineReader) ReadAllLines() ([]string, error)

ReadAllLines read all lines from the reader. return an error if any error occurred while read. If read all data succeed till and io.EOF, nil error will be returned.

func (*LineReader) ReadLine

func (r *LineReader) ReadLine() (string, error)

ReadLine read and return one line, not including the end-of-line bytes. ReadLine either returns a non-nil line or it returns an error, never both. No indication or error is given if the input ends without a final line end. An io.EOF error would be returned if already read to the end of reader.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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