Documentation
¶
Index ¶
- func Append(filePath string, content string) error
- func AppendByte(filePath string, content []byte) (err error)
- func ContentToExtName(lType string) string
- func DetectMime(content []byte) string
- func ExtByContent(content []byte) string
- func MimeToExt(ct string) string
- func Read(filePath string) ([]byte, error)
- func Write(filePath string, content string) error
- func WriteByte(filePath string, content []byte) error
- type DirEntryInfo
- type FileNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendByte ¶ added in v0.1.3
AppendByte 将字节追加到文件末尾,若文件不存在则创建
func ContentToExtName ¶ added in v0.1.3
ContentToExtName 根据给定的 content-type 返回不带点的扩展名(例如 "png")。 函数对输入做基本规范化(Trim + ToLower + 去掉参数),并使用内部映射作兜底。
func DetectMime ¶ added in v0.1.3
DetectMime 根据字节内容返回 MIME 类型,使用 http.DetectContentType
func ExtByContent ¶ added in v0.1.3
ExtByContent 根据内容推断合适的文件后缀(含点),若无法推断则返回空字符串
func MimeToExt ¶ added in v0.1.3
MimeToExt 返回不带点的扩展名(例如 "png"),若未知返回空字符串。 优先使用标准库 mime.ExtensionsByType 获取扩展名,失败后回退到 ContentToExtName 的映射。
Types ¶
type DirEntryInfo ¶ added in v0.1.3
type DirEntryInfo = FileNode
DirEntryInfo 是 FileNode 的别名,提供更语义化的类型名以便迁移使用
type FileNode ¶ added in v0.1.3
type FileNode struct {
Name string `json:"name"` // 文件或目录名
RelPath string `json:"rel_path"` // 相对路径,相对于传入的根目录
AbsPath string `json:"abs_path"` // 绝对路径
IsFile bool `json:"is_file"` // 是否为文件
DirName string `json:"dir_name"` // 所在目录名
DirRelPath string `json:"dir_rel"` // 所在目录相对路径
DirAbsPath string `json:"dir_abs"` // 所在目录绝对路径
IsDir bool `json:"is_dir"` // 是否为目录
}
FileNode 表示目录中每一项的返回信息
Click to show internal directories.
Click to hide internal directories.