kk_file

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeImage = 1
)

Variables

View Source
var (
	Jpeg = FileType{
		ContentType: "image/jpeg",
		Suffix:      ".jpg",
	}

	Avif = FileType{
		ContentType: "image/avif",
		Suffix:      ".avif",
	}

	Gif = FileType{
		ContentType: "image/gif",
		Suffix:      ".gif",
	}

	Png = FileType{
		ContentType: "image/png",
		Suffix:      ".png",
	}
	Heic = FileType{
		ContentType: "image/heic",
		Suffix:      ".heic",
	}
)

Functions

func AppendOrCreateFile

func AppendOrCreateFile(filePath string, content []byte) error

AppendOrCreateFile 函数接受文件路径和要追加的内容作为参数 如果文件存在,则追加内容 如果文件不存在,则创建文件并写入内容 如果文件所在目录不存在,则先创建目录

func ConvertFileSizeMB

func ConvertFileSizeMB(size int64) float64

ConvertFileSizeMB 转换文件大小B->MB

func CreateAndOpenFile

func CreateAndOpenFile(filePath string) (file *os.File, err error)

CreateAndOpenFile 创建文件并以追加的方式打开文件

func DetectTypeByBytes

func DetectTypeByBytes(bytes []byte) string

DetectTypeByBytes 通过文件头判断图片类型

func DetectTypeByFile

func DetectTypeByFile[T *os.File | *multipart.FileHeader](file T) string

DetectTypeByFile 通过文件头判断图片类型 支持os.File和multipart.FileHeader 二选一

func DirTree

func DirTree(dir string, result *[]FileNode) error

DirTree collects all files and directories in a directory.

func ScanCodeToTxT

func ScanCodeToTxT(absPath string, ext string)

ScanCodeToTxT 扫描文件夹下的所有文件,并导出到output.txt文件中 ext 文件后缀 .go .dart

func Tail

func Tail(filename string, n uint64) (buff []string, err error)

Tail reads the last n lines of a file

Types

type FileNode

type FileNode struct {
	FileName string
	FilePath string
	Children []FileNode
}

type FileSize

type FileSize int
const (
	KB FileSize = 1 << 10 // 1KB
	MB FileSize = 1 << 20 // 1MB
	GB FileSize = 1 << 30 // 1GB
)

func (FileSize) Int

func (fs FileSize) Int() int

func (FileSize) Int64

func (fs FileSize) Int64() int64

type FileType

type FileType struct {
	ContentType string
	Suffix      string
}

func New

func New(contentType string) FileType

Jump to

Keyboard shortcuts

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