files

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package files

Package files

Package files

Index

Constants

View Source
const (
	KB = 1 << 10
	MB = KB << 10
	GB = MB << 10
	TB = GB << 10
)

Variables

View Source
var (
	ErrFileOverDir = errors.New(
		"fsync: trying to overwrite a non-empty directory with a file")
)

Functions

func ClearFile

func ClearFile(f string) error

ClearFile 清空文件内容

func Copy

func Copy(src, dst string) error

Copy 复制文件到某路径

func CreateFile

func CreateFile(f string, perm os.FileMode, dirPerm os.FileMode) (*os.File, error)

CreateFile 创建文件如果不存在

func GetContent

func GetContent(f string) []byte

GetContent 读取文件内容 错误时返回空

func GetFileMode

func GetFileMode(f string) os.FileMode

GetFileMode 获取文件类型

func GetModTime

func GetModTime(f string) time.Time

GetModTime 获取文件修改时间 文件不存在时返回当前时间

func GetSize

func GetSize(f string) int64

GetSize 获取文件大小

func GetSizeReadable

func GetSizeReadable(f string) string

GetSizeReadable 可读性更好的fileSize

func IsExist

func IsExist(path string) bool

IsExist 文件或文件夹是否存在

func IsFile

func IsFile(path string) bool

IsFile 是否为文件

func IsFolder

func IsFolder(path string) bool

IsFolder 是否为文件夹

func IsZip

func IsZip(f string) bool

func MkDir

func MkDir(p string, perm os.FileMode) error

MkDir 按照子目录创建目录

func Name

func Name(f string) string

Name 获取文件的base名称

func RmDir

func RmDir(p string) error

RmDir 删除目录

func RmFile

func RmFile(f string) error

func SetFileMode

func SetFileMode(f string, perm os.FileMode) error

SetFileMode chmod修改文件权限

func SetFileOwn

func SetFileOwn(f string, uid int, gid int) error

SetFileOwn chown修改属主 user id group id

func Sync

func Sync(dst, src string) error

Sync copies files and directories inside src into dst.

func SyncTo

func SyncTo(to string, srcs ...string) error

SyncTo syncs srcs files and directories into to directory.

func TmpFile

func TmpFile(f string) (*os.File, error)

TmpFile 创建/tmp下的临时文件

func UnZip

func UnZip(f string, target string) error

UnZip 解压文件

func Zip

func Zip(f string, target string) error

Zip 压缩文件或目录到指定路径 例如: Zip(/tmp/1.txt, /tmp/1.zip) target不存在zip后缀时默认添加

Types

type FileInfo

type FileInfo interface {
	Name() string
	IsDir() bool
}

FileInfo contains the shared methods between os.FileInfo and fs.DirEntry.

type Syncer

type Syncer struct {
	// Set this to true to delete files in the destination that don't exist
	// in the source.
	Delete bool
	// To allow certain files to remain in the destination, implement this function.
	// Return true to skip file, false to delete.
	// Note that src may be either os.FileInfo or fs.DirEntry depending on the file system.
	DeleteFilter func(f FileInfo) bool
	// By default, modification times are synced. This can be turned off by
	// setting this to true.
	NoTimes bool
	// NoChmod disables permission mode syncing.
	NoChmod bool
	// Implement this function to skip Chmod syncing for only certain files
	// or directories. Return true to skip Chmod.
	ChmodFilter func(dst, src os.FileInfo) bool

	SrcFs  afero.Fs
	DestFs afero.Fs

	// exclude
	Exclude     []string
	ExcludeFunc func(f FileInfo) bool
}

Type Syncer provides functions for syncing files.

func NewSyncer

func NewSyncer() *Syncer

NewSyncer creates a new instance of Syncer with default options.

func (*Syncer) Sync

func (s *Syncer) Sync(dst, src string) error

Sync copies files and directories inside src into dst.

func (*Syncer) SyncTo

func (s *Syncer) SyncTo(to string, srcs ...string) error

SyncTo syncs srcs files or directories into to directory.

Jump to

Keyboard shortcuts

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