From c7e3c77befe8e49efcba154ad6caddb71322a6d4 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 16 May 2014 17:03:16 -0700 Subject: [PATCH] refactor newReader --- tail.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tail.go b/tail.go index 61cf465..7202580 100644 --- a/tail.go +++ b/tail.go @@ -214,7 +214,7 @@ func (tail *Tail) tailFileSync() { } } - tail.reader = tail.newReader() + tail.openReader() // Read line by line. for { @@ -295,7 +295,7 @@ func (tail *Tail) waitForChanges() error { return err } tail.Logger.Printf("Successfully reopened %s", tail.Filename) - tail.reader = tail.newReader() + tail.openReader() return nil } else { tail.Logger.Printf("Stopping tail as file no longer exists: %s", tail.Filename) @@ -308,7 +308,7 @@ func (tail *Tail) waitForChanges() error { return err } tail.Logger.Printf("Successfully reopened truncated %s", tail.Filename) - tail.reader = tail.newReader() + tail.openReader() return nil case <-tail.Dying(): return ErrStop @@ -316,12 +316,12 @@ func (tail *Tail) waitForChanges() error { panic("unreachable") } -func (tail *Tail) newReader() *bufio.Reader { +func (tail *Tail) openReader() { if tail.MaxLineSize > 0 { // add 2 to account for newline characters - return bufio.NewReaderSize(tail.file, tail.MaxLineSize+2) + tail.reader = bufio.NewReaderSize(tail.file, tail.MaxLineSize+2) } else { - return bufio.NewReader(tail.file) + tail.reader = bufio.NewReader(tail.file) } }