summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-02-10 12:03:13 -0800
committerJosh Bleecher Snyder <josh@tailscale.com>2021-02-10 12:03:13 -0800
commit5555728c727866c251aa2f3dce2a2f30983165b8 (patch)
tree624cc4afdbae390a32c3030c50de8721fba8cf2a
parent7e201806b10af3d484643b03dc5b5b1dcec85c54 (diff)
downloadtailscale-josh/simplify-filch.tar.xz
tailscale-josh/simplify-filch.zip
logtail/filch: use bufio.ScanLinesjosh/simplify-filch
splitLines here is identical to bufio.ScanLines, except that bufio.ScanLines removes \r in addition to \n. Trailing carriage returns shouldn't matter for our uses. Since bufio.ScanLines is the default for a new bufio.Scanner, we can delete the calls to Split too.
-rw-r--r--logtail/filch/filch.go16
1 files changed, 0 insertions, 16 deletions
diff --git a/logtail/filch/filch.go b/logtail/filch/filch.go
index 07d9b6203..00863ae4d 100644
--- a/logtail/filch/filch.go
+++ b/logtail/filch/filch.go
@@ -8,7 +8,6 @@ package filch
import (
"bufio"
- "bytes"
"fmt"
"io"
"os"
@@ -53,7 +52,6 @@ func (f *Filch) TryReadLine() ([]byte, error) {
return nil, err
}
f.altscan = bufio.NewScanner(f.alt)
- f.altscan.Split(splitLines)
return f.scan()
}
@@ -188,7 +186,6 @@ func New(filePrefix string, opts Options) (f *Filch, err error) {
}
if f.recovered > 0 {
f.altscan = bufio.NewScanner(f.alt)
- f.altscan.Split(splitLines)
}
f.OrigStderr = nil
@@ -228,16 +225,3 @@ func moveContents(dst, src *os.File) (err error) {
}
return nil
}
-
-func splitLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
- if atEOF && len(data) == 0 {
- return 0, nil, nil
- }
- if i := bytes.IndexByte(data, '\n'); i >= 0 {
- return i + 1, data[0 : i+1], nil
- }
- if atEOF {
- return len(data), data, nil
- }
- return 0, nil, nil
-}