summaryrefslogtreecommitdiffstats
path: root/pkg/utils/io.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-05-30 15:22:04 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-06-02 20:33:52 +1000
commit258eedb38c6e8692565d74a92e3590da477dea6b (patch)
treedb0a544b281184b04c704182e5a81f11172ee80e /pkg/utils/io.go
parentbc044c64b2315c3fb8c523fa0ae7ef71bcba3b31 (diff)
refactor
Diffstat (limited to 'pkg/utils/io.go')
-rw-r--r--pkg/utils/io.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/utils/io.go b/pkg/utils/io.go
new file mode 100644
index 000000000..d31c5fc07
--- /dev/null
+++ b/pkg/utils/io.go
@@ -0,0 +1,25 @@
+package utils
+
+import (
+ "bufio"
+ "os"
+)
+
+func ForEachLineInFile(path string, f func(string, int)) error {
+ file, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+
+ reader := bufio.NewReader(file)
+ for i := 0; true; i++ {
+ line, err := reader.ReadString('\n')
+ if err != nil {
+ break
+ }
+ f(line, i)
+ }
+
+ return nil
+}