Files
advent-of-code-2025/internal/file/file.go
T

40 lines
652 B
Go
Raw Normal View History

2025-12-01 06:49:26 -06:00
// Package file provides useful methods for interacting with files
package file
import (
"bufio"
"os"
)
2025-12-05 07:05:28 -06:00
// TODO: Implement a StreamLines method
// in the file package
2025-12-01 06:49:26 -06:00
func ReadLines(filePath string) []string {
lines := []string{}
file, openErr := os.Open(filePath)
if openErr != nil {
return lines
}
scanner := bufio.NewScanner(file)
for hasLine := scanner.Scan(); hasLine; hasLine = scanner.Scan() {
line := scanner.Text()
lines = append(lines, line)
}
return lines
}
func ReadAllText(filePath string) string {
fileContent, readErr := os.ReadFile(filePath)
if readErr != nil {
return ""
}
return string(fileContent)
}