remove: countlines from textreader
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// this could be made faster.
|
||||
@@ -106,3 +107,23 @@ func atoi(input []byte) (int, error) {
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func countLines(r io.Reader) (int, error) {
|
||||
var (
|
||||
lines int
|
||||
buf = make([]byte, os.Getpagesize()) // read via 16 KB blocks
|
||||
)
|
||||
|
||||
for {
|
||||
n, err := r.Read(buf)
|
||||
lines += bytes.Count(buf[:n], []byte{'\n'})
|
||||
|
||||
if err == io.EOF {
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return lines, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user