Files
android_development/tools/repo_diff/service/repodiff/persistence/filesystem/csv.go
Scott Lobdell 96629bd335 Base commit for service layer for repo diff tooling
Test: Changes are currently independent of the rest of this project. Tests can
currently manually be run with "make test". CL is large, but poses no
risk

Change-Id: Ia77e073df077257cab96b7ca4e1d99a900d029b2
2018-03-06 13:38:05 -08:00

45 lines
704 B
Go

package filesystem
import (
"bufio"
"encoding/csv"
"fmt"
"io"
"os"
"github.com/pkg/errors"
)
type lineHandler func(csvColumns []string)
func GenerateCSVLines(filePath string, handler lineHandler) error {
csvFile, err := os.Open(filePath)
if err != nil {
return errors.Wrap(
err,
fmt.Sprintf("Could not open %s", filePath),
)
}
reader := csv.NewReader(
bufio.NewReader(csvFile),
)
isFirstLine := true
for {
line, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
return errors.Wrap(
err,
fmt.Sprintf("Could not read line from file %s", filePath),
)
}
if !isFirstLine {
handler(line)
}
isFirstLine = false
}
return nil
}