rfile

package module
v0.0.0-...-073d0c7 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2018 License: BSD-3-Clause, MIT Imports: 3 Imported by: 0

README

rfile

Read a file in reverse line-by-line.

Inspired by: a gonuts discussion.

Documentation: in godoc.

...
  f, err := rfile.Open(file)
  if err != nil {
    // handle err
  }
  for {
    line, err := f.ReadLine()
    if err != nil {
      if err != io.EOF {
        // handle error
      }
      break // must be io.EOF
    }
    // do something with "line"
  }
  f.Close()
  ...

Documentation

Overview

Package rfile reads a file in reverse - line-by-line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tail

func Tail(file string, n int) ([]string, error)

Tail returns the last N lines of a file. If the file has fewer lines than 'n', the whole file will be returned.

Types

type Rfile

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

Rfile manages a file opened for reading line-by-line in reverse.

func Open

func Open(file string) (*Rfile, error)

Open returns Rfile handle to be read in reverse line-by-line.

func (*Rfile) Close

func (rf *Rfile) Close()

Close file that was opened.

func (*Rfile) ReadLine

func (rf *Rfile) ReadLine() (string, error)

ReadLine returns the next previous line, beginning with the last line in the file. When the beginning of the file is reached: "", io.EOF is returned.

Jump to

Keyboard shortcuts

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