fileutils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
	TiByte
	PiByte
	EiByte
)

IEC Sizes. kibis of bits

View Source
const (
	IByte = 1
	KByte = IByte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)

SI Sizes.

Variables

This section is empty.

Functions

func Bytes

func Bytes(s uint64) string

Bytes produces a human readable representation of an SI size.

See also: ParseBytes.

Bytes(82854982) -> 83 MB

func CalculateSHA256Byte added in v0.1.2

func CalculateSHA256Byte(data []byte) string

func CalculateSHA256Checksum

func CalculateSHA256Checksum(filePath string) (string, error)

func CheckFullPath added in v0.1.0

func CheckFullPath(path string) bool

func CheckLinuxPath added in v0.1.0

func CheckLinuxPath(path string) bool

func CheckWindowsPath added in v0.1.0

func CheckWindowsPath(path string) bool

func ChmodR

func ChmodR(path string, filePerm, dirPerm os.FileMode) error

ChmodR - Recursively chmod

func CollectFilePaths added in v0.1.2

func CollectFilePaths(rootPath string) ([]string, error)

CollectFilePaths collects all file paths from the given directory recursively

func CompressFilesZip added in v0.1.2

func CompressFilesZip(filePaths []string) ([]byte, error)

CompressFilesZip 将多个文件压缩成zip

func CopyDirectoryExcept added in v0.1.2

func CopyDirectoryExcept(sourceDir, targetDir string, excludeFiles []string) error

CopyDirectoryExcept copies all files and directories from sourceDir to targetDir except the excluded files.

func CopyFile

func CopyFile(src string, dst string) error

CopyFile - Copy a file from src to dst

func DecodeBase64OrRaw added in v0.1.2

func DecodeBase64OrRaw(data string) ([]byte, error)

DecodeBase64OrRaw attempts to decode base64 string, falls back to raw bytes if decoding fails

func DecompressBase64ToFiles added in v0.1.2

func DecompressBase64ToFiles(base64Data, outputDir string) error

DecompressBase64ToFiles 将base64字符串解压并提取文件到指定目录

func DecompressZipSubdirToRoot added in v0.1.2

func DecompressZipSubdirToRoot(zipData []byte, subdir, outputDir string) error

func DeflateBuf

func DeflateBuf(data []byte) []byte

DeflateBuf - Deflate a buffer using BestCompression (9)

func DetectContentType added in v0.1.2

func DetectContentType(data []byte) string

DetectContentType

func EncodeBase64OrRaw added in v0.1.2

func EncodeBase64OrRaw(data []byte) string

EncodeBase64OrRaw encodes the given data to base64 string, falls back to raw bytes if encoding fails

func Exist

func Exist(filePath string) bool

Exist - Check if a file exists

func ExtractTarGz

func ExtractTarGz(gzipPath string, dest string) error

ExtractTarGz extracts a .tar.gz file to the specified destination directory

func ExtractZip added in v0.1.2

func ExtractZip(zipData []byte, targetDir string) error

ExtractZip 解压zip文件到目标目录

func ExtractZipSubdir added in v0.1.2

func ExtractZipSubdir(zipData []byte, subdir, targetDir string) error

ExtractZipSubdir 解压指定子目录到目标路径

func ExtractZipWithFilter added in v0.1.2

func ExtractZipWithFilter(zipData []byte, targetDir string, filter func(string) bool) error

ExtractZipWithFilter 使用过滤器解压文件

func ForceRemoveAll

func ForceRemoveAll(rootPath string) error

func FormatWindowPath

func FormatWindowPath(path string) string

func GetExtensionByBytes added in v0.1.1

func GetExtensionByBytes(data []byte) (string, error)

func GetExtensionByPath added in v0.1.1

func GetExtensionByPath(filepath string) (string, error)

func IBytes

func IBytes(s uint64) string

IBytes produces a human readable representation of an IEC size.

See also: ParseBytes.

IBytes(82854982) -> 79 MiB

func MoveDirectory

func MoveDirectory(sourceDir, destDir string) error

func MoveFile

func MoveFile(sourcePath, destPath string) error

func ParseBytes

func ParseBytes(s string) (uint64, error)

ParseBytes parses a string representation of bytes into the number of bytes it represents.

See Also: Bytes, IBytes.

ParseBytes("42 MB") -> 42000000, nil ParseBytes("42 mib") -> 44040192, nil

func ReadFileFromTarGz

func ReadFileFromTarGz(tarGzFile string, tarPath string) ([]byte, error)

ReadFileFromTarGz - Read a file from a tar.gz file in-memory

func RemoveFile

func RemoveFile(filePath string) error

RemoveFile - Remove a file from src to dst

func ResolvePath

func ResolvePath(in string) string

ResolvePath - Resolve a path from an assumed root path

func UnzipOneWithBytes added in v0.1.0

func UnzipOneWithBytes(content []byte) ([]byte, error)

UnzipOneWithBytes 从zip字节数据中解压单个文件并返回其内容

func WithTempDir added in v0.1.2

func WithTempDir(prefix string, fn func(tempDir string) error) error

WithTempDir executes a function with a temporary directory, automatically cleaning up

Types

This section is empty.

Jump to

Keyboard shortcuts

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