fs

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DownloadWhitelist = map[string]bool{
	"pdf":    true,
	"ppt":    true,
	"pptx":   true,
	"xls":    true,
	"xlsx":   true,
	"doc":    true,
	"docx":   true,
	"png":    true,
	"jpg":    true,
	"bmp":    true,
	"svg":    true,
	"tif":    true,
	"mp3":    true,
	"mid":    true,
	"wma":    true,
	"wav":    true,
	"mp4":    true,
	"swf":    true,
	"rm":     true,
	"rmvb":   true,
	"mpg":    true,
	"mpeg":   true,
	"avi":    true,
	"mov":    true,
	"wmv":    true,
	"rar":    true,
	"zip":    true,
	"tar":    true,
	"gz":     true,
	"tar.gz": true,
	"7z":     true,
	"pkg":    true,
	"dmg":    true,
	"dep":    true,
	"txt":    true,
	"json":   true,
	"jsonc":  true,
	"html":   true,
	"conf":   true,
	"css":    true,
	"js":     true,
	"htm":    true,
}

DownloadWhitelist the file system allow download

View Source
var FileSystemHandlers = map[string]process.Handler{
	"readfile":        processReadFile,
	"readfilebuffer":  processReadFileBuffer,
	"writefile":       processWirteFile,
	"writefilebuffer": processWriteFileBuffer,
	"readdir":         processReadDir,
	"mkdir":           processMkdir,
	"mkdirall":        processMkdirAll,
	"mkdirtemp":       processMkdirTemp,
	"remove":          processRemove,
	"removeall":       processRemoveAll,
	"exists":          processExists,
	"isdir":           processIsDir,
	"isfile":          processIsFile,
	"islink":          processIsLink,
	"chmod":           processChmod,
	"size":            processSize,
	"mode":            processMode,
	"modtime":         processModTime,
	"basename":        processBaseName,
	"dirname":         processDirName,
	"extname":         processExtName,
	"mimetype":        processMimeType,
	"move":            processMove,
	"copy":            processCopy,
	"upload":          processUpload,
	"download":        processDownload,
}

FileSystemHandlers the file system handlers

View Source
var FileSystems = map[string]FileSystem{
	"system": system.New(),
}

FileSystems Register filesystems

View Source
var RootFileSystems = map[string]FileSystem{}

RootFileSystems high-level filesystem

Functions

func BaseName

func BaseName(name string) string

BaseName return the base name

func Chmod

func Chmod(xfs FileSystem, name string, mode uint32) error

Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError. A different subset of the mode bits are used, depending on the operating system. On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used. On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file. On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used.

func Copy

func Copy(xfs FileSystem, name string, dst string) error

Copy copy from src to dst

func DirName

func DirName(name string) string

DirName return the dir name

func Exists

func Exists(xfs FileSystem, name string) (bool, error)

Exists returns a boolean indicating whether the error is known to report that a file or directory already exists. It is satisfied by ErrExist as well as some syscall errors.

func ExtName

func ExtName(name string) string

ExtName return the extension name

func IsDir

func IsDir(xfs FileSystem, name string) bool

IsDir check the given path is dir

func IsFile

func IsFile(xfs FileSystem, name string) bool

IsFile check the given path is file

func IsLink(xfs FileSystem, name string) bool

IsLink check the given path is symbolic link

func MimeType

func MimeType(xfs FileSystem, name string) (string, error)

MimeType return the MimeType

func Mkdir

func Mkdir(xfs FileSystem, dir string, perm uint32) error

Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type *PathError.

func MkdirAll

func MkdirAll(xfs FileSystem, dir string, perm uint32) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

func MkdirTemp

func MkdirTemp(xfs FileSystem, dir string, pattern string) (string, error)

MkdirTemp creates a new temporary directory in the directory dir and returns the pathname of the new directory. The new directory's name is generated by adding a random string to the end of pattern. If pattern includes a "*", the random string replaces the last "*" instead. If dir is the empty string, MkdirTemp uses the default directory for temporary files, as returned by TempDir. Multiple programs or goroutines calling MkdirTemp simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when it is no longer needed.

func ModTime

func ModTime(xfs FileSystem, name string) (time.Time, error)

ModTime return the file modification time

func Mode

func Mode(xfs FileSystem, name string) (uint32, error)

Mode return the file mode bits

func Move

func Move(xfs FileSystem, name string, dst string) error

Move move from src to dst

func ReadDir

func ReadDir(xfs FileSystem, dir string, recursive bool) ([]string, error)

ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error.

func ReadFile

func ReadFile(xfs FileSystem, file string) ([]byte, error)

ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

func RegisterConnector

func RegisterConnector(c connector.Connector) error

RegisterConnector register a fileSystem via connector

func Remove

func Remove(xfs FileSystem, name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func RemoveAll

func RemoveAll(xfs FileSystem, name string) error

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *PathError.

func Size

func Size(xfs FileSystem, name string) (int, error)

Size return the length in bytes for regular files; system-dependent for others

func WriteFile

func WriteFile(xfs FileSystem, file string, data []byte, perm uint32) (int, error)

WriteFile writes data to the named file, creating it if necessary.

If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions.

Types

type FileSystem

type FileSystem interface {
	ReadFile(file string) ([]byte, error)
	WriteFile(file string, data []byte, perm uint32) (int, error)

	ReadDir(dir string, recursive bool) ([]string, error)
	Mkdir(dir string, perm uint32) error
	MkdirAll(dir string, perm uint32) error
	MkdirTemp(dir string, pattern string) (string, error)

	Remove(name string) error
	RemoveAll(name string) error

	Exists(name string) (bool, error)
	Size(name string) (int, error)
	Mode(name string) (uint32, error)
	ModTime(name string) (time.Time, error)

	Chmod(name string, mode uint32) error
	IsDir(name string) bool
	IsFile(name string) bool
	IsLink(name string) bool

	Move(oldpath string, newpath string) error
	Copy(src string, dest string) error

	MimeType(name string) (string, error)
}

FileSystem the filesystem io interface

func Get

func Get(name string) (FileSystem, error)

Get pick a filesystem via the given name

func MustGet

func MustGet(name string) FileSystem

MustGet pick a filesystem via the given name

func MustRootGet

func MustRootGet(name string) FileSystem

MustRootGet pick a filesystem via the given name

func Register

func Register(id string, fs FileSystem) FileSystem

Register a FileSystem

func RootGet

func RootGet(name string) (FileSystem, error)

RootGet pick a filesystem via the given name (root first)

func RootRegister

func RootRegister(id string, fs FileSystem) FileSystem

RootRegister Register a root FileSystem

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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