afs

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 5 Imported by: 0

README

afs

afs (abstract-file-system,抽象文件系统接口)提供一组简单易用的文件访问接口

Documentation

Index

Constants

View Source
const (
	WantToMakeDir    = 0x0001
	WantToReadFile   = 0x0002
	WantToWriteFile  = 0x0004
	WantToCreateFile = 0x0008
)

Variables

This section is empty.

Functions

func SetDefaultFSFactory

func SetDefaultFSFactory(factory FileSystemFactory) error

SetDefaultFSFactory 在调用 Default() 之前,必须设置默认的工厂

Types

type FS

type FS interface {
	NewPath(path string) Path

	ListRoots() []Path

	CreateTempFile(prefix, suffix string, dir Path) (Path, error)

	// PathSeparator return ';'(windows) | ':'(unix)
	PathSeparator() string

	// Separator return '/'(unix) | '\'(windows)
	Separator() string

	// 设置一个函数,用来处理默认的I/O选项
	SetDefaultOptionsHandler(fn OptionsHandlerFunc) error
}

FS 是表示文件系统的接口

func Default

func Default() FS

Default 获取默认的FS对象

type FileIO

type FileIO interface {
	Path() Path

	OpenReader(opt *Options) (io.ReadCloser, error)

	OpenWriter(opt *Options) (io.WriteCloser, error)

	OpenSeekerR(opt *Options) (io.ReadSeekCloser, error)

	OpenSeekerW(opt *Options) (WriteSeekCloser, error)

	OpenSeekerRW(opt *Options) (ReadWriteSeekCloser, error)

	ReadText(opt *Options) (string, error)

	WriteText(text string, opt *Options) error

	WriteBinary(b []byte, opt *Options) error

	ReadBinary(opt *Options) ([]byte, error)
}

FileIO ...

type FileInfo

type FileInfo interface {
	Path() Path

	Length() int64

	CreatedAt() time.Time

	UpdatedAt() time.Time

	Mode() fs.FileMode

	Exists() bool

	IsFile() bool

	IsDirectory() bool
}

FileInfo ...

type FileSystemFactory

type FileSystemFactory interface {
	Create() FS
}

FileSystemFactory 是用来创建 FS 对象的工厂

type NopReaderPool added in v0.0.5

type NopReaderPool struct {
}

NopReaderPool ...

func (*NopReaderPool) Clean added in v0.0.5

func (inst *NopReaderPool) Clean()

Clean ...

func (*NopReaderPool) Close added in v0.0.5

func (inst *NopReaderPool) Close() error

Close ...

func (*NopReaderPool) OpenReader added in v0.0.5

func (inst *NopReaderPool) OpenReader(file Path, op *Options) (io.ReadSeekCloser, error)

OpenReader ...

type Options

type Options struct {

	// fill with fs.ModeXXX
	Permission fs.FileMode

	// fill with os.O_xxxx
	Flag int

	Mkdirs    bool
	Create    bool
	Read      bool
	Write     bool
	File      bool
	Directory bool
}

Options ...

func (*Options) ToCreateFile added in v0.0.9

func (inst *Options) ToCreateFile() *Options

func (*Options) ToMakeDir added in v0.0.9

func (inst *Options) ToMakeDir() *Options

func (*Options) ToReadFile added in v0.0.9

func (inst *Options) ToReadFile() *Options

func (*Options) ToWriteFile added in v0.0.9

func (inst *Options) ToWriteFile() *Options

type OptionsHandlerFunc added in v0.0.8

type OptionsHandlerFunc func(path string, opt *Options, want WantOption) *Options

OptionsHandlerFunc 函数用于为I/O操作准备选项

type Path

type Path interface {
	Exists() bool

	IsFile() bool

	IsDirectory() bool

	GetName() string

	GetPath() string

	GetInfo() FileInfo

	String() string

	GetFS() FS

	GetParent() Path

	GetChild(name string) Path

	ListNames() []string

	ListPaths() []string

	ListChildren() []Path

	Mkdir(opt *Options) error

	Mkdirs(opt *Options) error

	Delete() error

	Create(opt *Options) error

	CreateWithData(data []byte, opt *Options) error

	CreateWithSource(src io.Reader, opt *Options) error

	MoveTo(dst Path, opt *Options) error

	CopyTo(dst Path, opt *Options) error

	GetIO() FileIO
}

Path 是表示绝对路径的接口

type ReadWriteSeekCloser added in v0.0.4

type ReadWriteSeekCloser interface {
	io.Closer
	io.ReadWriteSeeker
}

ReadWriteSeekCloser ...

type ReaderPool added in v0.0.5

type ReaderPool interface {
	io.Closer
	Clean()
	OpenReader(file Path, op *Options) (io.ReadSeekCloser, error)
}

ReaderPool ...

type WantOption added in v0.0.9

type WantOption int32

type WriteSeekCloser added in v0.0.4

type WriteSeekCloser interface {
	io.Closer
	io.WriteSeeker
}

WriteSeekCloser ...

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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