resource

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 21 Imported by: 2

README

resource

资源文件夹管理,基于 fsnotify 实现自动更新

Documentation

Index

Constants

View Source
const (
	Byte = "{Byte}"
	KB   = "{KB}"
	MB   = "{MB}"
	GB   = "{GB}"
	TB   = "{TB}"
)

Variables

This section is empty.

Functions

func ReadLine added in v0.2.0

func ReadLine() (r []string)

func Split added in v0.2.0

func Split(path string) []string

Types

type Anchor

type Anchor struct {
	// contains filtered or unexported fields
}

func (*Anchor) IsDir

func (a *Anchor) IsDir(f func(root, dir *Folder, name string, info os.FileInfo)) *Anchor

func (*Anchor) IsFile

func (a *Anchor) IsFile(f func(root *Folder, file *File, name string, info os.FileInfo)) *Anchor

type Explorer added in v0.2.1

type Explorer interface {
	Path(file ...string) string

	Find(name string) *File
	Touch(name string, size int64) (*File, bool)
	MakeTo(path string) Explorer

	MkdirAll()
	RemoveAll()
}

type File

type File struct {
	Name string  `cmps:"1" json:"name"`
	Back *Folder `json:"-"`
	Size Size    `json:"size"`
	// contains filtered or unexported fields
}

func (*File) Load added in v0.2.0

func (f *File) Load() ([]byte, error)

func (*File) MustLoad added in v0.3.0

func (f *File) MustLoad() []byte

func (*File) MustRead added in v0.3.0

func (f *File) MustRead() string

func (*File) MustRemove added in v0.3.0

func (f *File) MustRemove()

func (*File) MustStore added in v0.3.0

func (f *File) MustStore(data []byte)

func (*File) MustWrite added in v0.3.0

func (f *File) MustWrite(data string)

func (*File) Path

func (f *File) Path(file ...string) string

func (*File) Read added in v0.2.0

func (f *File) Read() (string, error)

func (*File) Remove added in v0.2.0

func (f *File) Remove() error

func (*File) Store added in v0.2.0

func (f *File) Store(data []byte) error

func (*File) String

func (f *File) String() string

func (*File) Write added in v0.2.0

func (f *File) Write(data string) error

type Folder

type Folder struct {
	File    `cmps:"1"`
	Files   cmps.SafeSlice[*File]   `json:"files"`
	Folders cmps.SafeSlice[*Folder] `json:"folders"`
}

func (*Folder) CD

func (f *Folder) CD(path string) *Folder

Warning: if you want to check the returning Explorer whether nil.

You need to use:

f.CD("xxx") == (*Folder)(nil)

Instead of:

f.CD("xxx") == nil

func (*Folder) Child

func (f *Folder) Child(path string) *Folder

func (*Folder) Create

func (f *Folder) Create(dirs []string) (size int64, isDir bool)

The dirs is used to describe the subdirectory under f.

func (*Folder) Delete

func (f *Folder) Delete(c interface{ Path(...string) string })

func (*Folder) Find

func (f *Folder) Find(name string) *File

func (*Folder) JumpTo added in v0.2.0

func (f *Folder) JumpTo(path string) *Folder

func (*Folder) List

func (f *Folder) List() Chan.Chan[fmt.Stringer]

func (*Folder) MakeTo added in v0.2.0

func (f *Folder) MakeTo(path string) Explorer

func (*Folder) Mkdir

func (f *Folder) Mkdir(path string) (*Folder, bool)

func (*Folder) MkdirAll added in v0.3.0

func (f *Folder) MkdirAll()

func (*Folder) RemoveAll added in v0.2.0

func (f *Folder) RemoveAll()

func (*Folder) Replace added in v0.2.0

func (f *Folder) Replace(path string) string

func (*Folder) String

func (f *Folder) String() string

func (*Folder) Touch

func (f *Folder) Touch(name string, size int64) (*File, bool)

func (*Folder) Transport

func (f *Folder) Transport(path string, names ...string) *Anchor

func (*Folder) Walk

func (f *Folder) Walk() int64

Use Walk() function when detect a new folder create or initialize *Folder.

type Resource

type Resource struct {
	event.AsyncEvent[fsnotify.Op]

	Root    *Folder
	Watcher *fsnotify.Watcher
	// contains filtered or unexported fields
}

func (*Resource) Close added in v0.2.0

func (r *Resource) Close()

func (*Resource) Init

func (r *Resource) Init(root string) *Resource

func (*Resource) MakeDir added in v0.2.0

func (r *Resource) MakeDir(path string)

func (*Resource) Shell

func (r *Resource) Shell(read func() []string)

func (*Resource) Store added in v0.2.0

func (r *Resource) Store(path string, data []byte)

func (*Resource) Write added in v0.2.0

func (r *Resource) Write(path, data string)

type Size

type Size struct {
	// contains filtered or unexported fields
}

func (*Size) Add

func (s *Size) Add(size int64)

func (Size) Base

func (s Size) Base(base string) string

func (Size) Byte

func (s Size) Byte() int64

func (Size) Format

func (s Size) Format(f string, limit ...string) string

func (*Size) MarshalJSON added in v0.3.2

func (s *Size) MarshalJSON() ([]byte, error)

func (*Size) Set

func (s *Size) Set(size int64)

func (Size) String

func (s Size) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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