Documentation
¶
Overview ¶
Package fileutil provides functions for doing things with files, like reading them line by line, etc
Index ¶
- func Exists(path string) (bool, error)
- func Pwd() (string, error)
- func ReadLinesChannel(filePath string) (<-chan string, error)
- func ReadLinesSlice(path string) ([]string, error)
- func ReadPropertiesFile(fileName string) (map[string]string, error)
- func TempFileName(prefix, suffix string) string
- func WriteLinesSlice(lines []string, path string) error
- type SynchronizedFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadLinesChannel ¶
ReadLinesChannel reads a text file line by line into a channel.
c, err := fileutil.ReadLinesChannel(fileName) if err != nil { log.Fatalf("readLines: %s\n", err) } for line := range c { fmt.Printf(" Line: %s\n", line) }
nil is returned (with the error) if there is an error opening the file
func ReadLinesSlice ¶
ReadLinesSlice reads a text file line by line into a slice of strings. Not recommended for use with very large files due to the memory needed.
lines, err := fileutil.ReadLinesSlice(filePath) if err != nil { log.Fatalf("readLines: %s\n", err) } for i, line := range lines { fmt.Printf(" Line: %d %s\n", i, line) }
nil is returned if there is an error opening the file
func ReadPropertiesFile ¶
Reads name-value pairs from a properties file Property file has lines in the format of "name = value" (leading and trailing spaces are ignored)
func TempFileName ¶
TempFileName generates a temporary filename for use in testing or whatever
func WriteLinesSlice ¶
WriteLinesSlice writes the given slice of lines to the given file.
Types ¶
type SynchronizedFile ¶
type SynchronizedFile struct {
// contains filtered or unexported fields
}
SynchronizedFile wraps an os.File pointer with a mutex
func NewSynchronizedFile ¶
func NewSynchronizedFile(f *os.File) *SynchronizedFile
NewSynchronizedFile synchronizes writing to a writer
func (*SynchronizedFile) WriteString ¶
func (sf *SynchronizedFile) WriteString(text string) (int, error)
WriteString writes to the file