files

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package files provides minor support for dealing with files.

Index

Constants

This section is empty.

Variables

View Source
var (
	GDefaultCopyFileAdvancedOptions = CopyFileAdvancedOptions{
		DstCreateDir:         false,
		DstCreateDirFileMode: 0755,
		Sync:                 false,
	}
)

Functions

func CopyDirRecursive added in v0.1.1

func CopyDirRecursive(from, to string) error

CopyDirRecursive copies all the content of a directory into another path.

func CopyFile added in v0.1.1

func CopyFile(src, dst string) error

CopyFile

func CopyFileAdvanced added in v0.1.1

func CopyFileAdvanced(src, dst string, options *CopyFileAdvancedOptions) error

func DeleteFile added in v0.1.8

func DeleteFile(path string) error

DeleteFile is a convenience function that ignores the error if the file didn't exist already.

func DirExists

func DirExists(path string) (bool, error)

DirExists check whether the directory exists and is a directory (not another type of file).

func GlobalFileCache

func GlobalFileCache() *fileCache

func StatFile

func StatFile(path string) (fs.FileInfo, bool, error)

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

func StatFileErrorf(err error, format string, args ...any) error

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

func ToUnixPath(path string) string

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 CopyFileAdvancedOptions struct {
	// DstCreateDir determines whether to try to create the owning directory of the dst file.
	DstCreateDir         bool
	DstCreateDirFileMode fs.FileMode

	// Sync ensures any buffered data is sent immediatelly.
	Sync bool
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL