Documentation
¶
Index ¶
- Constants
- func CopyDir(srcPath string, dstPath string, mode os.FileMode) error
- func CopyFile(src, dst string) error
- func DirSize(path string) (int64, error)
- func EnsureDir(dir string, perm os.FileMode) error
- func Exists(path string) bool
- func FileMode(path string) os.FileMode
- func FileSize(path string) int64
- func HashBytes(data []byte, alg string) (string, error)
- func HashFile(path string, alg string) (string, error)
- func HashReader(r io.Reader, alg string) (string, error)
- func IsDir(path string) bool
- func IsEmpty(path string) (bool, error)
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsSameFile(path1, path2 string) bool
- func IsWritable(path string) bool
- func IsZipFile(filepath string) (bool, error)
- func RemoveAllFiles(dir string) error
- func SafeRename(src, dst string) error
- func SaveFile(fileHeader *multipart.FileHeader, dstPath, fileType, expectedHash string) error
- func UnzipSafe(source, destination string, maxSize int64, maxFiles int) error
- func ZipDir(folderPath, destPath string) (rerr error)
- func ZipFiles(destZipPath string, srcFilePaths ...string) (rerr error)
Constants ¶
View Source
const ( MD5 = "md5" SHA1 = "sha1" SHA256 = "sha256" SHA512 = "sha512" )
Variables ¶
This section is empty.
Functions ¶
func HashReader ¶
流式哈希,alg为"md5"|"sha1"|"sha256"|"sha512"
func IsSameFile ¶ added in v0.1.7
IsSameFile 判断两个路径是否是同一个文件 (inode)
func RemoveAllFiles ¶ added in v0.1.7
RemoveAllFiles 删除目录下所有文件但保留目录本身
func SafeRename ¶ added in v0.1.7
SafeRename 原子替换文件 (Linux/Unix)
func SaveFile ¶
func SaveFile(fileHeader *multipart.FileHeader, dstPath, fileType, expectedHash string) error
SaveFile 保存上传的文件 增加了严格的安全校验 参数: fileHeader *multipart.FileHeader: 上传的文件 dstPath string: 文件保存的目标路径 fileType: 文件类型, 如 "application/zip",可以为空,表示不进行文件类型校验 expectedHash string: 预期的文件的哈希值,用于严格校验,为空表示不进行校验
func UnzipSafe ¶ added in v0.1.9
UnzipSafe 是一个经过安全加固的解压函数。 它能有效防御路径遍历(Zip Slip)、解压炸弹(Zip Bomb)、 符号链接攻击、不安全的文件权限以及非预期的文件类型(如管道、设备文件)。
参数:
source: zip 压缩包的文件路径。 destination: 解压目标目录。 maxSize: 允许解压的总大小上限(字节)。 maxFiles: 允许解压的文件数量上限。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.