Documentation ¶
Index ¶
- Constants
- Variables
- func AppendToFile(fpath, str string) error
- func CalcMD5(filepath string) (data []byte, err error)
- func CanOpenInFS(f fs.FS, filename string) bool
- func ChangedExtension(spath, ext string) string
- func CloneFile(dest, source string) error
- func CopyFile(dest, source string) (err error)
- func CountBytesOfFileInFS(f fs.FS, name string) (int64, error)
- func CreateSanitizedShortNameWithHash(name string) string
- func CreateTempFile(name string) (file *os.File, fpath string, err error)
- func CreateTempFilePath(name string) string
- func DeleteOldInSubFolders(dir string, sleep time.Duration, before time.Time, deleteRatio float32, ...) error
- func Exists(fpath string) bool
- func ExpandTildeInFilepath(path string) string
- func ForAllFileLines(path string, skipEmpty bool, line func(str string) bool) error
- func GetFilesFromPath(path, wildcards string, opts WalkOptions) (files []string, err error)
- func IsFolder(fpath string) bool
- func JoinPathParts(parts ...any) string
- func MakeDirAllIfNotExists(dir string) error
- func MakePathRelativeTo(path, rel string) string
- func MimeToExtension(smime string) string
- func Modified(filepath string) time.Time
- func NotExists(fpath string) bool
- func PeriodicFileBackup(filepath, suffixForOld string, maxMB int)
- func ReadBytesFromFileInFS(f fs.FS, name string) ([]byte, error)
- func ReadFromURLToFilepath(surl, filepath string, maxBytes int64) (path string, err error)
- func ReadLastLine(fpath string, pos int64) (line string, startpos, newpos int64, err error)
- func ReadStringFromFile(sfile string) (string, error)
- func ReadStringFromFileInFS(f fs.FS, name string) (string, error)
- func ReaderAtFromFileInFS(f fs.FS, name string) (reader io.ReaderAt, length int64, err error)
- func ReaderFromFileInFS(f fs.FS, name string) (reader io.Reader, err error)
- func RemoveAllQuicklyWithRename(dir string) error
- func RemoveContents(dir string) error
- func RemoveFolderWithContents(dir string) error
- func RemoveOldFilesFromFolder(folder, wildcard string, opt WalkOptions, olderThan time.Duration)
- func RemovedExtension(spath string) string
- func ReplaceHomeDirPrefixWithTilde(path string) string
- func SanitizeStringForFilePath(s string) string
- func SetModified(fpath string, t time.Time) error
- func SetOwnerAndMainGroup(fpath, owner string) error
- func Size(fpath string) int64
- func Split(spath string) (dir, name, stub, ext string)
- func TruncateFile(fpath string, maxBytes int64, reduce float64, fromEnd bool) error
- func Walk(folder, wildcards string, opts WalkOptions, ...) error
- func WorkingDirPathToAbsolute(wpath string) string
- func WriteBytesToFile(data []byte, sfile string) error
- func WriteStringToFile(str, sfile string) error
- func WriteToFileAtomically(fpath string, write func(file io.Writer) error) error
- type MultiFS
- func (m *MultiFS) Add(f fs.FS, fsname string)
- func (m *MultiFS) InsertFirst(f fs.FS, fsname string)
- func (m MultiFS) IsOpenable(filename string) (bool, string)
- func (m MultiFS) Open(filename string) (fs.File, error)
- func (m MultiFS) OpenReturningFSName(filename string) (fs.File, string, error)
- func (m MultiFS) Stat(filename string) (fs.FileInfo, string, error)
- type WalkOptions
Constants ¶
const ( PNGExt = ".png" JPEGExt = ".jpeg" JPGExt = ".jpg" )
Variables ¶
var ImageExtensions = []string{PNGExt, JPEGExt, JPGExt}
Functions ¶
func AppendToFile ¶
func ChangedExtension ¶
func CreateTempFilePath ¶
func DeleteOldInSubFolders ¶
func ExpandTildeInFilepath ¶
func ForAllFileLines ¶
func GetFilesFromPath ¶
func GetFilesFromPath(path, wildcards string, opts WalkOptions) (files []string, err error)
GetFilesFromPath returns a list of names of files inside path.
func JoinPathParts ¶
func MakeDirAllIfNotExists ¶
func MakePathRelativeTo ¶
func MimeToExtension ¶
func PeriodicFileBackup ¶
PeriodicFileBackup checks if *filepath* is larger than maxMB megabytes every *checkHours*. If so, the file is moved to a file in the same directory with a suffix before extension. "path/file_suffix.log".
func ReadFromURLToFilepath ¶
ReadFromURLToFilepath http.Get's the file at surl, and stores it in a file at filepath. If maxBytes != 0, it only downloads that many bytes. If filepath == "", it creates a temporary file using name from surl. The stored file is returned in path, or err if error.
func ReadLastLine ¶
ReadLastLine reads a file from end, until it encounters ascii 10/13, consuming them too. *startpos* is where it started reading at. *newpos* is where it ended. if pos is not zero, it starts at pos. zero means start from end.
func ReadStringFromFile ¶
func ReaderAtFromFileInFS ¶
ReaderAtFromFileInFS reads entire file to memory to be able to create a io.ReaderAt
func ReaderFromFileInFS ¶
func RemoveContents ¶
func RemoveOldFilesFromFolder ¶
func RemoveOldFilesFromFolder(folder, wildcard string, opt WalkOptions, olderThan time.Duration)
func RemovedExtension ¶
func SetOwnerAndMainGroup ¶
func TruncateFile ¶
if a file is > maxBytes, TruncateFile removes bytes from start or end to make it maxBytes*reduce large. This method is not atomical, more bytes can be added to fpath while it is working, and these will be lost, so a mutex or something should be used for appending to fpath if possible.
func Walk ¶
func Walk(folder, wildcards string, opts WalkOptions, got func(fpath string, info os.FileInfo) error) error
Walk walks though the contents of folder, calling got on each, matching names with tab-separated wildcards (if any). folders are entered without wildcard matching. info.IsDir can be checked to see if the content is a folder, and path.SkipDir / path.SkipAll can be returned to abort a sub-folder or all. Any other error returned from got stops all and returns that error.
func WorkingDirPathToAbsolute ¶
WorkingDirPathToAbsolute prefixes wpath with working dir. If wpath is absolute, it returns it as-is.
func WriteBytesToFile ¶
func WriteStringToFile ¶
Types ¶
type WalkOptions ¶
type WalkOptions int
const ( WalkOptionsNone WalkOptions = 0 WalkOptionRecursive WalkOptions = 1 << iota WalkOptionGiveFolders WalkOptionGiveHidden WalkOptionGiveNameOnly WalkOptionRelativePath )