Documentation
¶
Overview ¶
Package fileutil wraps standard library functions to get info about files and directories that is otherwise a little convoluted to work out every time it's needed.
In the future the package may add functions to help manipulate files and directories.
Index ¶
- func BaseNoext(name string) string
- func CopyFile(src, dst string) error
- func DetectContentType(rs io.ReadSeeker) (string, error)
- func FindFiles(base string) ([]string, error)
- func IsDir(p string) bool
- func IsEmpty(p string) bool
- func IsExist(p string) bool
- func IsFile(p string) bool
- func MD5(path string) (string, error)
- func ReadFileLines(p string) ([]string, error)
- func ReadFileLinesDie(p string) []string
- func ReadFileNonBlankNonCommentLines(p string) ([]string, error)
- func ReadFileNonBlankNonCommentLinesDie(p string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseNoext ¶
BaseNoext returns the basename of path (ie, the filename without the preceding path components) without the extension (what *I* sometimes erroneously think of as the "basename").
NB: uses package path, so meant to work on slash-separated paths.
func CopyFile ¶
Stolen from Russ Cox "Error Handling — Problem Overview" https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md
But also cf. CopyFile from Dave Cheney's github.com/pkg/fileutils
func DetectContentType ¶
func DetectContentType(rs io.ReadSeeker) (string, error)
Detect content-type without having the whole file in memory.
comment from reference: At most the first 512 bytes of data are used: https://golang.org/src/net/http/sniff.go?s=646:688#L11
ref: https://gist.github.com/rayrutjes/db9b9ea8e02255d62ce2 https://archive.is/iGqI9
func FindFiles ¶
FindFiles recursively finds (or lists) all files under base. Directories are ignored. It's like `find base type -f`. NOTE: This *will* return "hidden" files (files starting with a dot). I'm not sure if that's desireable, but for now the caller is responsible for filtering those out if they aren't wanted.
func ReadFileLines ¶
ReadFileLines is an error-returning version of ReadFileLinesDie. See description of ReadFileLinesDie for details.
func ReadFileLinesDie ¶
ReadFileLinesDie wraps ioutil.ReadFile with the additions of returning the lines of the file p as a string slice, and it takes care of getting rid of the final "" element caused by the final newline in the file. And, it dies if it encounters an error. This is obviously only for situations where that's appropriate, like solving puzzles.
func ReadFileNonBlankNonCommentLines ¶
ReadFileNonBlankNonCommentLines is like the above ReadFileLines functions, but ignores blank lines and lines starting with "#" and "//".
func ReadFileNonBlankNonCommentLinesDie ¶
ReadFileNonBlankNonCommentLinesDie is a panicing version of ReadFileNonBlankNonCommentLines.
Types ¶
This section is empty.