readlines

package
v0.0.0-...-f3d8a94 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Iter

func Iter(r io.Reader, maxSize int, fn func(line []byte) error) error

Iter reads lines from r and calls fn with each read line, not including the line terminator. If a line exceeds the given maximum size, it will be truncated and the rest of the line discarded. If fn returns a non-nil error, reading ends and the error is returned from Iter. When EOF is encountered, Read returns nil.

Example
package main

import (
	"code.google.com/p/rog-go/readlines"
	"fmt"
	"strings"
)

func main() {
	input := `one two
three
four

five`
	r := strings.NewReader(input)
	readlines.Iter(r, 1024*1024, func(line []byte) error {
		fmt.Printf("%q\n", line)
		return nil
	})
}
Output:

"one two"
"three"
"four"
""
"five"

Types

This section is empty.

Jump to

Keyboard shortcuts

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