Documentation
¶
Index ¶
- Constants
- Variables
- func AtomicWriteFile(path string, data []byte, perm os.FileMode) error
- func Bytes(s uint64) string
- func CalculateSHA256Byte(data []byte) string
- func CalculateSHA256Checksum(filePath string) (string, error)
- func CheckFullPath(path string) bool
- func CheckLinuxPath(path string) bool
- func CheckWindowsPath(path string) bool
- func ChmodR(path string, filePerm, dirPerm os.FileMode) error
- func CollectFilePaths(rootPath string) ([]string, error)
- func CompressFilesZip(filePaths []string) ([]byte, error)
- func CopyDirectoryExcept(sourceDir, targetDir string, excludeFiles []string) error
- func CopyFile(src string, dst string) error
- func DecodeBase64OrRaw(data string) ([]byte, error)
- func DecompressBase64ToFiles(base64Data, outputDir string) error
- func DecompressZipSubdirToRoot(zipData []byte, subdir, outputDir string) error
- func DeflateBuf(data []byte) []byte
- func DetectContentType(data []byte) string
- func EncodeBase64OrRaw(data []byte) string
- func Exist(filePath string) bool
- func ExtractTarGz(gzipPath string, dest string) error
- func ExtractZip(zipData []byte, targetDir string) error
- func ExtractZipFromFile(zipPath string, dest string) error
- func ExtractZipSubdir(zipData []byte, subdir, targetDir string) error
- func ExtractZipWithFilter(zipData []byte, targetDir string, filter func(string) bool) error
- func ForceRemoveAll(rootPath string) error
- func FormatWindowPath(path string) string
- func GetExtensionByBytes(data []byte) (string, error)
- func GetExtensionByPath(filepath string) (string, error)
- func IBytes(s uint64) string
- func MoveDirectory(sourceDir, destDir string) error
- func MoveFile(sourcePath, destPath string) error
- func ParseBytes(s string) (uint64, error)
- func ReadFileFromTarGz(tarGzFile string, tarPath string) ([]byte, error)
- func ReadFileFromZip(zipFile string, targetPath string) ([]byte, error)
- func RemoteBase(p string) string
- func RemoteDir(p string) string
- func RemoteJoin(elem ...string) string
- func RemoveFile(filePath string) error
- func ResolvePath(in string) string
- func SafeJoin(baseDir string, unsafeRelPath string) (string, error)
- func SanitizeBasename(unsafePath string) (string, error)
- func UnzipOneWithBytes(content []byte) ([]byte, error)
- func WithTempDir(prefix string, fn func(tempDir string) error) error
- type ArchiveFormat
Constants ¶
const ( Byte = 1 << (iota * 10) KiByte MiByte GiByte TiByte PiByte EiByte )
IEC Sizes. kibis of bits
const ( IByte = 1 KByte = IByte * 1000 MByte = KByte * 1000 GByte = MByte * 1000 TByte = GByte * 1000 PByte = TByte * 1000 EByte = PByte * 1000 )
SI Sizes.
Variables ¶
var ErrUnsafePath = errors.New("unsafe path")
Functions ¶
func AtomicWriteFile ¶ added in v0.3.0
AtomicWriteFile writes data to a file atomically via a temp file + rename. This prevents partial writes from corrupting existing files.
func Bytes ¶
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 CalculateSHA256Checksum ¶
func CheckFullPath ¶ added in v0.1.0
func CheckLinuxPath ¶ added in v0.1.0
func CheckWindowsPath ¶ added in v0.1.0
func CollectFilePaths ¶ added in v0.1.2
CollectFilePaths collects all file paths from the given directory recursively
func CompressFilesZip ¶ added in v0.1.2
CompressFilesZip 将多个文件压缩成zip
func CopyDirectoryExcept ¶ added in v0.1.2
CopyDirectoryExcept copies all files and directories from sourceDir to targetDir except the excluded files.
func DecodeBase64OrRaw ¶ added in v0.1.2
DecodeBase64OrRaw attempts to decode base64 string, falls back to raw bytes if decoding fails
func DecompressBase64ToFiles ¶ added in v0.1.2
DecompressBase64ToFiles 将base64字符串解压并提取文件到指定目录
func DecompressZipSubdirToRoot ¶ added in v0.1.2
func DeflateBuf ¶
DeflateBuf - Deflate a buffer using BestCompression (9)
func DetectContentType ¶ added in v0.1.2
DetectContentType
func EncodeBase64OrRaw ¶ added in v0.1.2
EncodeBase64OrRaw encodes the given data to base64 string, falls back to raw bytes if encoding fails
func ExtractTarGz ¶
ExtractTarGz extracts a .tar.gz file to the specified destination directory
func ExtractZip ¶ added in v0.1.2
ExtractZip 解压zip文件到目标目录
func ExtractZipFromFile ¶ added in v0.3.0
ExtractZipFromFile extracts a zip file from disk to the destination directory
func ExtractZipSubdir ¶ added in v0.1.2
ExtractZipSubdir 解压指定子目录到目标路径
func ExtractZipWithFilter ¶ added in v0.1.2
ExtractZipWithFilter 使用过滤器解压文件
func ForceRemoveAll ¶
func FormatWindowPath ¶
func GetExtensionByBytes ¶ added in v0.1.1
func GetExtensionByPath ¶ added in v0.1.1
func IBytes ¶
IBytes produces a human readable representation of an IEC size.
See also: ParseBytes.
IBytes(82854982) -> 79 MiB
func MoveDirectory ¶
func ParseBytes ¶
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 ¶
ReadFileFromTarGz - Read a file from a tar.gz file in-memory
func ReadFileFromZip ¶ added in v0.3.0
ReadFileFromZip reads a single file from a zip archive by path
func RemoteBase ¶ added in v0.3.0
RemoteBase extracts the last element of a remote path that may use either forward or backward slashes, working correctly on any host OS.
func RemoteJoin ¶ added in v0.3.0
RemoteJoin joins remote path elements using forward slashes, suitable for building implant-side paths that work across OSes.
func ResolvePath ¶
ResolvePath - Resolve a path from an assumed root path
func SafeJoin ¶ added in v0.3.0
SafeJoin joins baseDir and unsafeRelPath and ensures the final path stays within baseDir. It rejects absolute paths and parent directory traversal ("..").
func SanitizeBasename ¶ added in v0.3.0
SanitizeBasename extracts and validates a single safe filename component from an untrusted path-like input. It normalizes Windows separators and rejects empty, "." and "..".
func UnzipOneWithBytes ¶ added in v0.1.0
UnzipOneWithBytes 从zip字节数据中解压单个文件并返回其内容
Types ¶
type ArchiveFormat ¶ added in v0.3.0
type ArchiveFormat int
ArchiveFormat represents a supported archive type.
const ( ArchiveUnknown ArchiveFormat = iota ArchiveTarGz ArchiveZip )
func DetectArchiveFormat ¶ added in v0.3.0
func DetectArchiveFormat(path string) (ArchiveFormat, error)
DetectArchiveFormat detects archive format by extension first, then magic bytes.