fileUtil

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PathSeparatorStr = string(os.PathSeparator)

Variables

This section is empty.

Functions

func ComputeFileHMAC

func ComputeFileHMAC(filePath string, key []byte) (string, error)

ComputeFileHMAC 计算指定文件的HMAC-SM3值

参数:

  • filePath: 要计算的文件路径
  • key: 用于HMAC计算的密钥

返回值:

  • string: 计算得到的HMAC十六进制字符串
  • error: 操作过程中遇到的错误

func ComputeFileHMACAndWrite

func ComputeFileHMACAndWrite(filePath string, key []byte) error

ComputeFileHMACAndWrite 计算指定文件的HMAC值并写入.hmac文件

参数:

filePath: 要计算HMAC的文件路径
key: 用于HMAC计算的密钥

返回:

error: 操作过程中发生的错误,包括HMAC计算失败或文件写入失败

func Copy

func Copy(srcFile, dstFile string) error

Copy 复制文件或目录。如果目标路径不存在,会自动创建对应目录。 参数:

  • srcFile: 源文件或目录路径。
  • dstFile: 目标文件或目录路径。

返回值:

  • error: 错误信息。

func GetExecDir

func GetExecDir() string

GetExecDir 返回当前执行文件所在的绝对路径(已解析符号链接)

func GetSystemRootDir

func GetSystemRootDir() string

GetSystemRootDir 返回操作系统安装位置的根目录 Windows: C:\ (基于 SystemDrive/SystemRoot 环境变量) Unix: /

func MandatoryValidateHMAC

func MandatoryValidateHMAC(filePath string, key []byte) error

MandatoryValidateHMAC 校验文件及其HMAC签名文件是否存在并验证签名

参数:

filePath - 需要校验的文件路径
key - 用于HMAC校验的密钥

返回:

error - 如果HMAC文件不存在或校验失败则返回错误

注意:

  • 会查找同目录下以.hmac为后缀的HMAC签名文件进行比对

func Mov

func Mov(srcFile, dstFile string) error

Mov 移动文件或目录。如果目标路径已存在,会覆盖目标文件或目录。 参数:

  • srcFile: 源文件或目录路径。
  • dstFile: 目标文件或目录路径。

返回值:

  • error: 错误信息。

func PathExists

func PathExists(path string) (bool, error)

PathExists 检查指定路径是否存在。 参数:

  • path: 需要检查的文件或目录路径。

返回值:

  • bool: 如果路径存在,返回 true;否则返回 false。
  • error: 如果检查过程中发生错误(非“路径不存在”错误),返回该错误;否则返回 nil。

注意:

  • 如果路径不存在,不会返回错误,而是返回 false 和 nil。
  • 其他错误(如权限不足)会直接返回。

func ReadFileLines

func ReadFileLines(path string, delim byte) []string

ReadFileLines 读取文件内容并按指定分隔符分割为多行字符串。 参数:

  • path: 文件路径。
  • delim: 行分隔符。

返回值:

  • []string: 分割后的字符串数组。

func ReadFileLinesTrimDelim

func ReadFileLinesTrimDelim(path string, delim byte, isTrim bool) []string

func ValidateHMAC

func ValidateHMAC(filePath string, key []byte) error

ValidateHMAC 验证指定文件的HMAC签名是否匹配 参数:

  • filePath: 要验证的文件路径
  • key: 用于HMAC计算的密钥

返回:

  • error: 如果验证失败或发生错误则返回错误信息,验证成功返回nil

注意:

  • 会查找同目录下以.hmac为后缀的HMAC签名文件进行比对

Types

This section is empty.

Jump to

Keyboard shortcuts

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