Documentation ¶
Overview ¶
Package files provides minor support for dealing with files.
Index ¶
- Variables
- func CopyDirRecursive(from, to string) error
- func CopyFile(src, dst string) error
- func CopyFileAdvanced(src, dst string, options *CopyFileAdvancedOptions) error
- func DeleteFile(path string) error
- func DirExists(path string) (bool, error)
- func GlobalFileCache() *fileCache
- func StatFile(path string) (fs.FileInfo, bool, error)
- func StatFileErrorf(err error, format string, args ...any) error
- func ToUnixPath(path string) string
- type CopyFileAdvancedOptions
- type LoadedFile
- type LoadedFilePosition
Constants ¶
This section is empty.
Variables ¶
var ( GDefaultCopyFileAdvancedOptions = CopyFileAdvancedOptions{ DstCreateDir: false, DstCreateDirFileMode: 0755, Sync: false, } )
Functions ¶
func CopyDirRecursive ¶ added in v0.1.1
CopyDirRecursive copies all the content of a directory into another path.
func CopyFileAdvanced ¶ added in v0.1.1
func CopyFileAdvanced(src, dst string, options *CopyFileAdvancedOptions) error
func DeleteFile ¶ added in v0.1.8
DeleteFile is a convenience function that ignores the error if the file didn't exist already.
func DirExists ¶
DirExists check whether the directory exists and is a directory (not another type of file).
func GlobalFileCache ¶
func GlobalFileCache() *fileCache
func StatFile ¶
StatFile returns the file info of the file if it can be done. If the file does not exists, the returned file info will be nil.
func StatFileErrorf ¶ added in v0.1.9
StatFileErrorf is an utility function to deal with the two possible error modes of |StatFile|. Useful when we don't care about the difference of an error or file not found.
Usage: ``` stat, found, err := StatFile(path)
if err != nil || !found { return StatFileErrorf(err, "statting %q", path) }
```
func ToUnixPath ¶ added in v0.1.1
ToUnixPath standardizes the path to be Unix-like. This is useful for making paths work uniformly between Windows and Linux.
Types ¶
type CopyFileAdvancedOptions ¶ added in v0.1.1
type LoadedFile ¶
type LoadedFile struct { Key string Data []byte FromFile bool Stat fs.FileInfo // contains filtered or unexported fields }
func LoadFileFromPath ¶
func LoadFileFromPath(path string) (*LoadedFile, error)
LoadFileFromPath attempts to load a file from a path and will store it in the global cache.
func LoadFileFromPathWithKey ¶
func LoadFileFromPathWithKey(key, path string, overwrite bool) (*LoadedFile, error)
LoadFileFromPathWithKey is a more advanced way of loading files that permit to insert it in an specific key, rather than using the abs path, as it is normally done. |overwrite| refers to whether we allow people to overwrite keys or not.
func NewFromData ¶
func NewFromData(key string, data []byte, overwrite bool) (*LoadedFile, error)
NewFromData creates a in-memory loaded file from the given data and stores it in the cache with the given key. From that moment on, it works similarly to a loaded file read from a file. |overwrite| refers to whether we allow people to overwrite keys or not.
func QueryKey ¶
func QueryKey(key string) (bool, *LoadedFile)
QueryKey checks to see if the key is in the global cache, and if so, returns the loaded file. For files loaded as path, the key would the absolute path as returned by |filepath.Abs|.
func (*LoadedFile) Lines ¶
func (lf *LoadedFile) Lines() ([]string, error)
Lines lazily parses the content of the file into lines.
func (*LoadedFile) Path ¶
func (lf *LoadedFile) Path() string
Path returns the Key as a path if the file was loaded from file rather than a buffer. Returns empty otherwise.
type LoadedFilePosition ¶
type LoadedFilePosition struct { File *LoadedFile Line int Char int }
LoadedFilePosition represents a single position (character) within a loaded file.
func NewLoadedFilePosition ¶
func NewLoadedFilePosition(lf *LoadedFile, line, char int) *LoadedFilePosition