Documentation ¶
Overview ¶
Package files 文件操作
包含了文件状态的快速判断, 大小计算 文件/文件夹的创建 移动 拷贝 删除 内置的Rsync命令调用 一个Serial串流文件流写入类帮助连续写入
Package files ¶
Package files ¶
Package files ¶
Package files ¶
Package files ¶
Package files ¶
Package files
Index ¶
- Constants
- Variables
- func AutoName(dst string) string
- func CalcSize(s int64) string
- func ClearFile(f string) error
- func Copy(src, dst string) error
- func CreateFile(f string, perm os.FileMode, dirPerm os.FileMode) (*os.File, error)
- func GetContent(f string) []byte
- func GetFileMode(f string) os.FileMode
- func GetModTime(f string) time.Time
- func GetSize(f string) int64
- func GetSizeReadable(f string) string
- func IsExist(path string) bool
- func IsFile(path string) bool
- func IsFolder(path string) bool
- func IsZip(f string) bool
- func MkDir(p string, perm os.FileMode) error
- func Name(f string) string
- func RmDir(p string) error
- func RmFile(f string) error
- func Rsync(src, dst string) error
- func RsyncAndTar(src, dst string, postClear bool) error
- func SetFileMode(f string, perm os.FileMode) error
- func SetFileOwn(f string, uid int, gid int) error
- func Sync(dst, src string) error
- func SyncTo(to string, srcs ...string) error
- func Tar(file, src string) error
- func TmpFile(f string) (*os.File, error)
- func UnZip(f string, target string) error
- func Zip(f string, target string) error
- type FileInfo
- type Serial
- type Syncer
Constants ¶
View Source
const ( Mask = 0022 ReadOnlyMode = 0444 WriteOnlyMode = 0222 UsrReadOnlyMode = 0400 UsrWriteOnlyMode = 0200 GReadOnlyMode = 0440 GWriteOnlyMode = 0220 RWMode = 0666 UsrRWMode = 0600 GRWMode = 0660 XMode = 0777 UsrXMode = 0700 GXMode = 0770 FileMode = 0640 XFileMode = 0700 DirMode = 0750 TmpMode = 0660 )
常用的文件权限mode Usr uid G gid
View Source
const ( KB = 1 << 10 MB = KB << 10 GB = MB << 10 TB = GB << 10 )
View Source
const ( RsyncCMD = "rsync -q -p -backup %s %s" TarCMD = "tar -zcf %s.tar.gz %s" )
Variables ¶
View Source
var (
ErrFileOverDir = errors.New(
"fsync: trying to overwrite a non-empty directory with a file")
)
View Source
var TmpDir = os.TempDir()
Functions ¶
func CreateFile ¶
CreateFile 创建文件如果不存在
func RsyncAndTar ¶ added in v1.0.9
RsyncAndTar 自动备份并压缩 eg: RsyncAndTar("/test", "/tmp/back", false) 会自动压缩目录到/tmp/back-timestamp.tar.gz
func SetFileOwn ¶
SetFileOwn chown修改属主 user id group id
Types ¶
type Serial ¶ added in v1.0.9
type Serial struct {
// contains filtered or unexported fields
}
func (*Serial) ExportSerial ¶ added in v1.0.9
ExportSerial 导出流到指定writer 默认为os.stdout
func (*Serial) ToFileSerial ¶ added in v1.0.9
ToFileSerial 存储到文件 默认存储为s.name.txt || timestamp.txt
func (*Serial) WriteSerial ¶ added in v1.0.9
WriteSerial 写入可读性强的string
func (*Serial) WriteSerialRaw ¶ added in v1.0.9
WriteSerialRaw 写入bytes
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.
Click to show internal directories.
Click to hide internal directories.