file

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)

Variables

This section is empty.

Functions

func ByteCountIEC

func ByteCountIEC(b int) string

func CheckNotExist

func CheckNotExist(src string) bool

CheckNotExist check if the img exists

func CheckPermission

func CheckPermission(src string) bool

CheckPermission check if the img has permission

func CreateCurrentDateDir

func CreateCurrentDateDir(rootPath string, perm os.FileMode) (string, error)

* 根据当前日期在指定根目录下创建多级目录 *

func CreateDateDir

func CreateDateDir(rootPath string, datetime time.Time, perm os.FileMode) (string, error)

* 根据指定的日期在指定的目录下创建多级目录 *

func CreateDir

func CreateDir(perm os.FileMode, args ...string) (string, error)

* 创建多级目录 *

func DeleteFile

func DeleteFile(filename string, args ...string) error

* 删除文件 *

func FileCreate

func FileCreate(content bytes.Buffer, name string)

func FileExist

func FileExist(path string) bool

func FileIsExists

func FileIsExists(filename string) bool

* 判断文件是否存在 *

func FileMonitoringById

func FileMonitoringById(ctx context.Context, filePth string, id string, group string, hookfn func(context.Context, string, string, []byte))

func FormatFileSize

func FormatFileSize(fileSize int64) (size string)

字节的单位转换 保留两位小数

func GetAbsolutePath

func GetAbsolutePath(filePath string) string

* 获取文件绝对全路径 *

func GetCurrentPath

func GetCurrentPath() string

获取当前路径,比如:E:/abc/data/test

func GetExt

func GetExt(fileName string) string

GetExt get the img ext

func GetFileContent

func GetFileContent(fullFilename string) ([]byte, error)

* 获取文件内容 *

func GetFilePath

func GetFilePath(filePath string) (string, string)

* 获取路径里的路径和文件名 *

func GetFileSize

func GetFileSize(filename string) int64

获取文件大小

func GetFileType

func GetFileType(p string) (string, error)

GetFileType 获取文件类型

func GetFilename

func GetFilename(filePath string) (string, string, string)

* 获取路径里的文件名,不带扩展名的文件名,扩展名 *

func GetParentDirectory

func GetParentDirectory(directory string) string

func GetRelativePath

func GetRelativePath(fullpath string) string

* 获取全文件路径的相对路径 *

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize get the img size

func IsDirectory

func IsDirectory(filename string) bool

func IsFile

func IsFile(filename string) bool

func IsHiddenFile

func IsHiddenFile(name string) bool

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir create a directory if it does not exist

func MkDir

func MkDir(src string) error

MkDir create a directory

func MkFileIfNotExist

func MkFileIfNotExist(path string)

func MkdirIfNotExist

func MkdirIfNotExist(path string)

func MoveFile

func MoveFile(srcFilename, dstPath string, creationDate time.Time) (string, error)

* 移动文件(全路径源文件,目的路径,日期,会根据日期自动创建路径然后连接到目的路径后) *

func MustOpenFile added in v0.0.9

func MustOpenFile(fileName, filePath string) (*os.File, error)

MustOpen maximize trying to open the img

func NormalizeEOL

func NormalizeEOL(input []byte) []byte

NormalizeEOL will convert Windows (CRLF) and Mac (CR) EOLs to UNIX (LF)

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

func OpenFile added in v0.0.9

func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

Open a img according to a specific mode

func ParseFileContentType

func ParseFileContentType(fileName string) string

func PathCreate

func PathCreate(dir string) error

func PathExist

func PathExist(addr string) bool

PathExist 判断目录是否存在

func SaveFile

func SaveFile(data []byte, filename, basePath string, args ...string) (string, error)

* 保存文件 *

func UploadFileTo

func UploadFileTo(fh *multipart.FileHeader, destDirectory string) (int64, error)

Types

type FileInfo

type FileInfo struct {
	Filename string `form:"filename" json:"filename"` //原始文件名(test.jpg)
	Data     []byte `form:"data" json:"data"`         //文件字节切片
	Size     int64  `form:"size" json:"size"`         //大小(单位:字节)
	Duration int64  `form:"duration" json:"duration"` //时长(单位:秒)
	Path     string `form:"path" json:"path"`         //全路径(本地磁盘或第三方文件系统)
}

func GetHttpRequestFile

func GetHttpRequestFile(req *http.Request, args ...int32) (*FileInfo, error)

* 获取Http请求里的文件数据 * maxSize: 文件大小限制,0表示不限制 *

func SaveHttpFile

func SaveHttpFile(req *http.Request, filename, basePath string, maxSize int32, args ...string) (*FileInfo, error)

* 保存Http 上传的文件到磁盘指定目录(返回客户端原文件名,大小,全文件路径,错误) *

type FileInfoList

type FileInfoList []*FileInfo

type IFileSize

type IFileSize interface {
	Size() int64
}

type ReplaceHelper

type ReplaceHelper struct {
	Root    string //路径
	OldText string //需要替换的文本
	NewText string //新的文本
}

func (*ReplaceHelper) DoWrok

func (h *ReplaceHelper) DoWrok() error

Jump to

Keyboard shortcuts

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