Documentation ¶
Index ¶
- func Close(closer io.Closer)
- func EmptyReader() io.Reader
- func ForEachLine(r io.Reader, consume func(line string)) error
- func ForEachLineWithEncoding(r io.Reader, encoding encoding.Encoding, consume func(line string)) error
- func ReadAll(r io.Reader) ([]byte, error)
- func ReadAllLines(r io.Reader) ([]string, error)
- func ReadAllLinesWithEncoding(r io.Reader, enc encoding.Encoding) ([]string, error)
- func ReadAllString(r io.Reader) (string, error)
- func ReadAllStringWithEncoding(r io.Reader, encoding encoding.Encoding) (string, error)
- type LineReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶
Close a resource, and ignore error. Useful for avoiding warning when use with defer: defer iox.Close(r)
func ForEachLine ¶ added in v1.2.0
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
ForEachLine 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 ReadAllLines ¶
ReadAllLines read all data as string lines, till EOF, return a lines slice. The reader will be left unclosed
func ReadAllLinesWithEncoding ¶
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
ReadAllString read and return all data as string in reader
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)
ReadAllLine 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.