photoprism/pkg/fs/readlines.go
Michael Mayer fe28c7d284 Backend: Add support for .ppignore files #233 #287
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-03 14:40:59 +02:00

35 lines
517 B
Go

package fs
import (
"bufio"
"io"
"os"
"strings"
)
// ReadLines returns all lines in a text file as string slice.
func ReadLines(fileName string) (lines []string, err error) {
file, err := os.Open(fileName)
if err != nil {
return lines, err
}
defer file.Close()
reader := bufio.NewReader(file)
for {
line, _, err := reader.ReadLine()
if err == io.EOF {
break
} else if err != nil {
return lines, err
}
lines = append(lines, strings.TrimSpace(string(line)))
}
return lines, nil
}