gfx

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 18 Imported by: 9

README

gfx

Golang文件操作扩展库,包含工作和生活中关于文件操作的各种有用的使用方法,包括

  • 更友好的API
  • 文件创建
  • 文件删除
  • 文件复制
  • 一切皆可配置
    • 文件名
    • 扩展名
    • 文件名匹配模式
    • 匹配方法

感谢

jetbrains-variant-4.png

Documentation

Index

Constants

View Source
const (
	CheckTypeAll checkType = 1
	CheckTypeAny checkType = 2
)
View Source
const (
	// TypeFile 文件
	TypeFile _type = 1
	// TypeDir 目录
	TypeDir _type = 2
)
View Source
const (
	// WriteModeSkip 跳过
	WriteModeSkip writeMode = 1
	// WriteModeOverride 覆盖
	WriteModeOverride writeMode = 2
	// WriteModeError 返回错误
	WriteModeError writeMode = 3
	// WriteModeRename 重命名
	WriteModeRename writeMode = 4
)

Variables

This section is empty.

Functions

func All

func All(dir string, opts ...walkOption) (filenames []string, err error)

All 取得目录下所有文件,包含子目录 默认文件匹配所有文件

func ContentType

func ContentType(path string) (contentType string, err error)

ContentType 获得文件的类型

func ContentTypeForFile

func ContentTypeForFile(file *os.File) (contentType string, err error)

ContentTypeForFile 获得文件的类型

func Copy

func Copy(from string, to string, opts ...copyOption) (err error)

Copy 文件复制 如果文件有冲突,默认使用覆盖模式

func Create

func Create(path string, opts ...option) (err error)

Create 创建文件或者目录 默认创建文件 默认权限是0777

func Delete

func Delete(filename string) error

Delete 删除文件或者目录

func Dir

func Dir() *optionType

func Exists

func Exists(path string, opts ...existsOption) (final string, exists bool)

Exists 判断文件是否存在

func Ext

func Ext(ext string) *optionExtensions

Ext 文件扩展名

func Extension added in v0.0.5

func Extension(extension string) *optionExtensions

Extension 文件扩展名

func Extensions added in v0.0.5

func Extensions(extensions ...string) *optionExtensions

Extensions 文件扩展名列表

func File

func File() *optionType

File 配置类型为文件

func Is

func Is(path string, opts ...isOption) (is bool, err error)

Is 判断所给路径是否为文件或者目录

func Matchable

func Matchable(matchable matchable) *optionMatchable

Matchable 配置文件是否可被浏览

func Mode

func Mode(mode os.FileMode) *optionMode

Mode 配置权限

func Move added in v0.1.4

func Move(from string, to string) error

Move 移动文件

func Name added in v0.0.8

func Name(path string, opts ...nameOption) (filename string)

Name 获得文件名称

func NewExistsOptions added in v0.0.4

func NewExistsOptions(opts ...existsOption) []existsOption

NewExistsOptions 快捷方式,解决接口不对外暴露不能引用的问题

func NewName added in v0.0.8

func NewName(original string) (new string)

NewName 新文件名,在避免文件名冲突的情况下

func NewOptions added in v0.1.1

func NewOptions(opts ...option) []option

NewOptions 暴露给外部使用的快捷方法

func NewOwner

func NewOwner(uid int, gid int) *owner

NewOwner 创建拥有者

func NewWalkOptions added in v0.1.1

func NewWalkOptions(opts ...walkOption) []walkOption

NewWalkOptions 暴露给外部使用的快捷方法

func Path added in v0.0.4

func Path(path string) *optionPaths

Path 路径

func Paths added in v0.0.5

func Paths(paths ...string) *optionPaths

Paths 路径列表

func Pattern

func Pattern(pattern string) *optionPattern

Pattern 模式匹配

func Prefix added in v0.0.9

func Prefix(prefix string) *optionPrefix

Prefix 前缀

func Regexp added in v0.0.8

func Regexp(regex string) *optionRegexp

Regexp 正则匹配

func Rename

func Rename(from string, to string) (err error)

Rename 重命名文件或者目录

func Source added in v0.0.9

func Source(source string) *optionSource

Source 源文件

func Suffix added in v0.1.3

func Suffix(suffix string) *optionSuffix

Suffix 以什么结束

func Type

func Type(_type _type) *optionType

Type 配置类型

func Unzip added in v0.0.9

func Unzip(source string, target string) (err error)

Unzip 解压

func ValidFilename

func ValidFilename(filename string) bool

ValidFilename 有效文件名(Windows标准)

func ValidFilepath

func ValidFilepath(filepath string) bool

ValidFilepath 有效文件夹名

func Walk added in v0.0.6

func Walk(dir string, handler walkHandler, opts ...walkOption) (err error)

Walk 浏览目录 默认文件匹配所有文件

func Watch added in v0.0.9

func Watch(path string, watcher Watcher) (err error)

func WriteMode

func WriteMode(mode writeMode) *optionWriteMode

WriteMode 配置复制模式

func Zip added in v0.0.9

func Zip(target string, source string, opts ...zipOption) (err error)

Zip 压缩

Types

type Watcher added in v0.0.9

type Watcher interface {
	// OnCreated 当文件被创建
	OnCreated(path string)

	// OnChanged 文件发生改变时
	OnChanged(path string)

	// OnDeleted 文件被删除时
	OnDeleted(path string)

	// OnRenamed 文件被重命名时
	OnRenamed(path string)

	// OnPermissionChanged 文件权限改变时
	OnPermissionChanged(path string)

	// OnError 当发生错误时
	OnError(err error)
}

Watcher 文件监控

Jump to

Keyboard shortcuts

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