package module
v0.0.0-...-1b945b3 Latest Latest

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

Go to latest
Published: Feb 13, 2019 License: MIT Imports: 4 Imported by: 616



go-linereader (Golang package: linereader) is a package for Go that breaks up the input from an io.Reader into multiple lines. It is a lot like bufio.Scanner, except you can specify timeouts that will push "lines" through after a certain amount of time. This lets you read lines, but return any data if a line isn't updated for some time.

Installation and Usage

Install using go get

Full documentation is available at

Below is an example of its usage ignoring errors:

// Assume r is some set io.Reader. Perhaps a file, network, anything.
var r io.Reader

// Initialize the line reader
lr := linereader.New(r)

// Get all the lines
for line := <-lr.Ch {
	// Do something with the line. This line will have the line separator
	// removed.




This section is empty.


This section is empty.


This section is empty.


type Reader

type Reader struct {
	Reader  io.Reader
	Timeout time.Duration

	// Ch is the output channel. This will be closed when there are no
	// more lines (io.EOF).
	Ch chan string
	// contains filtered or unexported fields

Reader takes an io.Reader and pushes the lines out onto the channel.

func New

func New(r io.Reader) *Reader

New creates a new Reader that reads lines from the io.Reader.

The Reader is already started when returned, so it is unsafe to modify any struct fields.

func (*Reader) Run

func (r *Reader) Run()

Run reads from the Reader and dispatches lines on the Ch channel.

This blocks and is usually called with `go` prefixed to dispatch onto a goroutine. It is safe to call this function multiple times; subsequent calls to Run will exit without running.

Jump to

Keyboard shortcuts

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