file

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(path string) (string, error)

AbsPath 获取绝对路径

func AppendFile

func AppendFile(path string, data []byte) error

AppendFile 追加内容到文件

func AppendLine

func AppendLine(path string, line string) error

AppendLine 追加一行到文件

func Chmod

func Chmod(path string, mode os.FileMode) error

Chmod 修改文件权限

func Chown

func Chown(path string, uid, gid int) error

Chown 修改文件所有者

func CleanPath

func CleanPath(path string) string

CleanPath 清理路径

func Copy

func Copy(src, dst string) error

Copy 复制文件

func CopyDir

func CopyDir(src, dst string, style ...string) error

CopyDir 递归复制目录

func CountFiles

func CountFiles(dir string) (int, error)

CountFiles 统计目录下的文件数量

func Exists

func Exists(path string) bool

Exists 检查文件或目录是否存在

func FindFiles

func FindFiles(dir string, pattern string) ([]string, error)

FindFiles 查找匹配模式的文件

func FormatSize

func FormatSize(size int64) string

FormatSize 格式化文件大小

func GetBaseName

func GetBaseName(path string) string

GetBaseName 获取文件名(不含扩展名)

func GetBlockDeviceSize

func GetBlockDeviceSize(path string) (int64, error)

GetBlockDeviceSize 获取块设备大小

func GetDir

func GetDir(path string) string

GetDir 获取目录路径

func GetDirSize

func GetDirSize(path string) (int64, error)

GetDirSize 获取目录总大小

func GetExtension

func GetExtension(path string) string

GetExtension 获取文件扩展名

func GetFileName

func GetFileName(path string) string

GetFileName 获取文件名(含扩展名)

func GetImageDimensions

func GetImageDimensions(path string) (width, height int, err error)

GetImageDimensions 获取图片尺寸

func GetMimeType

func GetMimeType(path string) string

GetMimeType 获取文件 MIME 类型(简单版本)

func GetSize

func GetSize(path string) (int64, error)

GetSize 获取文件大小

func HasEnoughSpace

func HasEnoughSpace(path string, required uint64) (bool, error)

HasEnoughSpace 检查路径是否有足够空间

func HeadFile

func HeadFile(path string, n int) ([]string, error)

HeadFile 读取文件开头 n 行

func ImageAspectRatio

func ImageAspectRatio(width, height int) string

ImageAspectRatio 计算图片宽高比

func IsArchive

func IsArchive(path string) bool

IsArchive 检查文件是否为压缩包

func IsAudio

func IsAudio(path string) bool

IsAudio 检查文件是否为音频

func IsBlockDevice

func IsBlockDevice(path string) bool

IsBlockDevice 检查是否为块设备

func IsDir

func IsDir(path string) bool

IsDir 检查是否为目录

func IsDocument

func IsDocument(path string) bool

IsDocument 检查文件是否为文档

func IsEmpty

func IsEmpty(path string) (bool, error)

IsEmpty 检查文件或目录是否为空

func IsFile

func IsFile(path string) bool

IsFile 检查是否为文件

func IsImage

func IsImage(path string) bool

IsImage 检查文件是否为图片

func IsImageByMagic

func IsImageByMagic(path string) bool

IsImageByMagic 通过魔数检查文件是否为图片

func IsSymlink(path string) bool

IsSymlink 检查是否为符号链接

func IsVideo

func IsVideo(path string) bool

IsVideo 检查文件是否为视频

func JoinPath

func JoinPath(elem ...string) string

JoinPath 连接路径

func ListAll

func ListAll(dir string) ([]string, error)

ListAll 列出目录下的所有文件和目录(非递归)

func ListDirs

func ListDirs(dir string) ([]string, error)

ListDirs 列出目录下的所有子目录(非递归)

func ListFiles

func ListFiles(dir string) ([]string, error)

ListFiles 列出目录下的所有文件(非递归)

func MD5

func MD5(path string) (string, error)

MD5 计算文件 MD5 哈希

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll 递归创建目录

func Move

func Move(src, dst string) error

Move 移动文件或目录

func ParseSize

func ParseSize(sizeStr string) (int64, error)

ParseSize 解析文件大小字符串

func ReadChunks

func ReadChunks(path string, chunkSize int, handler func(chunk []byte) error) error

ReadChunks 分块读取文件并处理

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile 读取文件内容

func ReadFileString

func ReadFileString(path string) (string, error)

ReadFileString 读取文件内容为字符串

func ReadLines

func ReadLines(path string) ([]string, error)

ReadLines 按行读取文件

func ReadLinesWithCallback

func ReadLinesWithCallback(path string, handler func(line string) error) error

ReadLinesWithCallback 按行读取文件并回调处理

func Remove

func Remove(path string) error

Remove 删除文件或空目录

func RemoveAll

func RemoveAll(path string) error

RemoveAll 递归删除文件或目录

func Rename

func Rename(oldPath, newPath string) error

Rename 重命名或移动文件

func SHA256

func SHA256(path string) (string, error)

SHA256 计算文件 SHA256 哈希

func SameFile

func SameFile(path1, path2 string) (bool, error)

SameFile 检查两个路径是否指向同一文件

func TailFile

func TailFile(path string, n int) ([]string, error)

TailFile 读取文件末尾 n 行

func Touch

func Touch(path string) error

Touch 创建空文件或更新文件时间戳

func Truncate

func Truncate(path string, size int64) error

Truncate 截断文件到指定大小

func WalkFiles

func WalkFiles(dir string, fn func(path string) error) error

WalkFiles 递归遍历目录下的所有文件

func WriteFile

func WriteFile(path string, data []byte, perm os.FileMode) error

WriteFile 写入文件

func WriteFileString

func WriteFileString(path string, content string, perm os.FileMode) error

WriteFileString 写入字符串到文件

Types

type BlockDevice

type BlockDevice struct {
	Path       string
	Size       int64
	MountPoint string
}

BlockDevice 块设备信息

type ChunkReader

type ChunkReader struct {
	// contains filtered or unexported fields
}

ChunkReader 分块读取器

func NewChunkReader

func NewChunkReader(path string, chunkSize int) (*ChunkReader, error)

NewChunkReader 创建分块读取器

func (*ChunkReader) Close

func (r *ChunkReader) Close() error

Close 关闭读取器

func (*ChunkReader) Read

func (r *ChunkReader) Read() ([]byte, error)

Read 读取一个块

type DiskUsage

type DiskUsage struct {
	Total     uint64  // 总空间
	Free      uint64  // 可用空间
	Used      uint64  // 已用空间
	UsedPct   float64 // 使用百分比
	Available uint64  // 用户可用空间
}

GetDiskUsage 获取磁盘使用情况

func GetDiskUsage

func GetDiskUsage(path string) (*DiskUsage, error)

GetDiskUsage 获取指定路径的磁盘使用情况

type ImageInfo

type ImageInfo struct {
	Width  int
	Height int
	Format string
}

ImageInfo 图片信息

func GetImageInfo

func GetImageInfo(path string) (*ImageInfo, error)

GetImageInfo 获取图片信息

type InodeUsage

type InodeUsage struct {
	Total   uint64
	Free    uint64
	Used    uint64
	UsedPct float64
}

GetInodeUsage 获取 inode 使用情况

func GetInodeUsage

func GetInodeUsage(path string) (*InodeUsage, error)

GetInodeUsage 获取指定路径的 inode 使用情况

type LineReader

type LineReader struct {
	// contains filtered or unexported fields
}

LineReader 行读取器

func NewLineReader

func NewLineReader(path string) (*LineReader, error)

NewLineReader 创建行读取器

func (*LineReader) Close

func (r *LineReader) Close() error

Close 关闭读取器

func (*LineReader) Err

func (r *LineReader) Err() error

Err 获取错误

func (*LineReader) ReadLine

func (r *LineReader) ReadLine() (string, bool)

ReadLine 读取一行

Jump to

Keyboard shortcuts

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