files

package
v0.0.0-...-7647e70 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 14 Imported by: 71

Documentation

Index

Constants

View Source
const (
	WhenceStart   = 0 // 文件开始处
	WhenceCurrent = 1 // 文件当前位置
	WhenceEnd     = 2 // 文件末尾处
)
View Source
const (
	SortTypeModifiedTime        = SortType(1) // 按最后修改时间
	SortTypeModifiedTimeReverse = SortType(2) // 按最后修改时间倒排序
	SortTypeName                = SortType(3) // 按名称
	SortTypeNameReverse         = SortType(4) // 按名称倒排序
	SortTypeSize                = SortType(5) // 按文件尺寸
	SortTypeSizeReverse         = SortType(6) // 按文件尺寸倒排序
	SortTypeKind                = SortType(7) // 按文件类型
	SortTypeKindReverse         = SortType(8) // 按文件类型倒排序
)

Variables

This section is empty.

Functions

func Sort

func Sort(files []*File, sortType ...SortType)

对一组文件进行排序

Types

type Appender

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

func NewAppender

func NewAppender(path string) (*Appender, error)

func (*Appender) Append

func (this *Appender) Append(b []byte) (n int, err error)

func (*Appender) AppendString

func (this *Appender) AppendString(s string) (n int, err error)

func (*Appender) Close

func (this *Appender) Close() error

func (*Appender) Lock

func (this *Appender) Lock()

func (*Appender) Sync

func (this *Appender) Sync() error

func (*Appender) Truncate

func (this *Appender) Truncate(size ...int64) error

func (*Appender) Unlock

func (this *Appender) Unlock()

type File

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

文件对象定义

func NewFile

func NewFile(path string) *File

包装新文件对象

func NewTmpFile

func NewTmpFile(file string) *File

func (*File) AbsPath

func (this *File) AbsPath() (string, error)

读取文件绝对路径

func (*File) Append

func (this *File) Append(data []byte) error

在文件末尾写入数据

func (*File) AppendString

func (this *File) AppendString(data string) error

在文件末尾写入字符串数据

func (*File) Appender

func (this *File) Appender() (*Appender, error)

取得Appender

func (*File) Child

func (this *File) Child(filename string) *File

目录下的文件

func (*File) Chmod

func (this *File) Chmod(mode os.FileMode) error

修改模式

func (*File) CopyTo

func (this *File) CopyTo(targetPath string) error

拷贝文件

func (*File) Create

func (this *File) Create() error

创建文件 如果是目录,则使用 Mkdir() 和 MkdirAll()

func (*File) Delete

func (this *File) Delete() error

删除文件或目录,但如果目录不为空则会失败

func (*File) DeleteAll

func (this *File) DeleteAll() error

删除文件或目录,即使目录不为空也会删除

func (*File) DeleteIfExists

func (this *File) DeleteIfExists() error

判断文件或目录是否存在,然后删除文件或目录,如果目录不为空则会失败

func (*File) Exists

func (this *File) Exists() bool

判断文件是否存在

func (*File) Ext

func (this *File) Ext() string

取得文件扩展名,带点符号

func (*File) Glob

func (this *File) Glob(pattern string) []*File

使用模式匹配查找当前目录下的文件

func (*File) IsDir

func (this *File) IsDir() bool

判断是否为目录

func (*File) IsFile

func (this *File) IsFile() bool

判断是否为文件

func (*File) LastModified

func (this *File) LastModified() (time.Time, error)

读取最后更新时间

func (*File) List

func (this *File) List() []*File

列出目录下级的子文件对象 注意只会返回下一级,不会递归深入子目录

func (*File) Md5

func (this *File) Md5() (string, error)

Md5 对文件内容进行Md5处理

func (*File) Mkdir

func (this *File) Mkdir(perm ...os.FileMode) error

创建目录,但如果父级目录不存在,则会失败

func (*File) MkdirAll

func (this *File) MkdirAll(perm ...os.FileMode) error

创建多级目录

func (*File) Mode

func (this *File) Mode() (os.FileMode, error)

读取文件模式

func (*File) Name

func (this *File) Name() string

取得文件名

func (*File) Parent

func (this *File) Parent() *File

取得父级目录对象

func (*File) Path

func (this *File) Path() string

读取文件路径

func (*File) Range

func (this *File) Range(iterator func(file *File))

递归地对当前目录下的所有子文件、目录应用迭代器

func (*File) ReadAll

func (this *File) ReadAll() ([]byte, error)

ReadAll 读取文件内容

func (*File) ReadAllString

func (this *File) ReadAllString() (string, error)

ReadAllString 读取文件内容并返回字符串形式

func (*File) Reader

func (this *File) Reader() (*Reader, error)

取得Reader

func (*File) Size

func (this *File) Size() (int64, error)

读取文件尺寸

func (*File) Stat

func (this *File) Stat() (*Stat, error)

取得文件统计信息

func (*File) Touch

func (this *File) Touch() error

修改文件的访问和修改时间为当前时间

func (*File) Write

func (this *File) Write(data []byte) error

写入数据

func (*File) WriteFormat

func (this *File) WriteFormat(format string, args ...interface{}) error

写入格式化的字符串数据

func (*File) WriteString

func (this *File) WriteString(data string) error

写入字符串数据

func (*File) Writer

func (this *File) Writer() (*Writer, error)

取得Writer

type Reader

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

func NewReader

func NewReader(path string) (*Reader, error)

func (*Reader) Close

func (this *Reader) Close() error

func (*Reader) Length

func (this *Reader) Length() (length int64, err error)

func (*Reader) Read

func (this *Reader) Read(size int64) []byte

func (*Reader) ReadAll

func (this *Reader) ReadAll() []byte

func (*Reader) ReadByte

func (this *Reader) ReadByte() []byte

func (*Reader) ReadJSON

func (this *Reader) ReadJSON(ptr interface{}) error

从JSON文件中读取数据

func (*Reader) ReadJSONMap

func (this *Reader) ReadJSONMap() (maps.Map, error)

从JSON文件中读取Map数据

func (*Reader) ReadLine

func (this *Reader) ReadLine() []byte

func (*Reader) ReadYAML

func (this *Reader) ReadYAML(ptr interface{}) error

从YAML文件中读取数据

func (*Reader) ReadYAMLMap

func (this *Reader) ReadYAMLMap() (maps.Map, error)

从YAML文件中读取Map数据

func (*Reader) Reset

func (this *Reader) Reset() error

func (*Reader) Seek

func (this *Reader) Seek(offset int64, whence ...Whence) (ret int64, err error)

移动文件指针到某个位置

type SortType

type SortType int

type Stat

type Stat struct {
	Name    string
	Size    int64
	Mode    os.FileMode
	ModTime time.Time
	IsDir   bool
}

type Whence

type Whence = int

type Writer

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

func NewWriter

func NewWriter(path string) (*Writer, error)

func (*Writer) Close

func (this *Writer) Close() error

func (*Writer) Lock

func (this *Writer) Lock()

func (*Writer) Seek

func (this *Writer) Seek(offset int64, whence ...Whence) (ret int64, err error)

func (*Writer) Sync

func (this *Writer) Sync() error

func (*Writer) Truncate

func (this *Writer) Truncate(size ...int64) error

func (*Writer) Unlock

func (this *Writer) Unlock()

func (*Writer) Write

func (this *Writer) Write(b []byte) (n int64, err error)

func (*Writer) WriteIOReader

func (this *Writer) WriteIOReader(reader io.Reader) (n int64, err error)

func (*Writer) WriteJSON

func (this *Writer) WriteJSON(value interface{}, pretty ...bool) (n int64, err error)

func (*Writer) WriteString

func (this *Writer) WriteString(s string) (n int64, err error)

func (*Writer) WriteYAML

func (this *Writer) WriteYAML(value interface{}) (n int64, err error)

Jump to

Keyboard shortcuts

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