iox

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: BSD-2-Clause Imports: 4 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 added in v1.9.0

func CloseAll(closers ...io.Closer)

CloseAll close multi closers and ignore errors

func EmptyReader added in v1.0.1

func EmptyReader() io.Reader

EmptyReader return a empty reader

func ForEachLine added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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

ReadAllString read and return all data as string in reader

func ReadAllStringWithEncoding added in v1.2.0

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 added in v1.8.2

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 added in v1.9.0

func TryCloseAll(resources ...interface{})

TryCloseAll try close multi resources, if it is a closer

Types

type LineReader added in v1.2.0

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 added in v1.2.0

func NewLineReader(r io.Reader) *LineReader

NewLineReader create new LineReader

func NewLineReaderSize added in v1.2.0

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

NewLineReaderSize create new LineReader with initial buf size

func (*LineReader) ForEachLine added in v1.2.0

func (r *LineReader) ForEachLine(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 (*LineReader) ReadAllLines added in v1.2.0

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

ReadAllLines read all lines in reader, return lines, and 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 added in v1.2.0

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