files

package
v0.0.0-...-512269d Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const FilePerm = 0644

FilePerm default permission of the newly created log file.

Variables

View Source
var ErrInvalidFsize = errors.New("fsize can`t be zero or negative")

ErrInvalidFsize invalid file size.

Functions

func AppendLine

func AppendLine(path string, content string) error

func CloseOneExec

func CloseOneExec(file *os.File)

CloseOnExec makes sure closing the file on process forking.

func CopyDir

func CopyDir(src string, dst string) error

CopyDir copy directory from src to dst

func CopyFile

func CopyFile(src, dist string) error

func CropImage

func CropImage(file string, width, height int) (err error)

CropImage 居中裁剪图片

func FileExt

func FileExt(fileName string) string

FileExt 获取文件后缀名

func FileType

func FileType(fileName string) string

FileType return image or file 根据后缀名区分文件是 file 还是 image

func GetDocumentExts

func GetDocumentExts() (exts []string)

func GetExts

func GetExts(extType string) (exts []string)

GetExts 获取文档类型对应的扩展名

func GetFileMD5

func GetFileMD5(filePath string) (string, error)

GetFileMD5 获取文件MD5值

func GetImageSize

func GetImageSize(file string) (width, height int, err error)

GetImageSize 获取图片宽高信息

func IsDocument

func IsDocument(ext string) bool

IsDocument 是否是文档

func IsImage

func IsImage(ext string) bool

IsImage 判断文件是否是图片

func ListFiles

func ListFiles(path string) []string

func LoadFile

func LoadFile(filename string) ([]byte, error)

LoadFile 读取文件内容

func LoadJsonToObject

func LoadJsonToObject(filename string, obj interface{}) error

LoadJsonToObject 读取json文件

func PathExists

func PathExists(path string) (bool, error)

PathExists check if the directory or file exits

func ReadCSV

func ReadCSV(filename string) ([]string, error)

func WriteBytesToFile

func WriteBytesToFile(fileName string, content []byte) error

func WriteString

func WriteString(path string, content string, append bool) error

func WriteStringToFile

func WriteStringToFile(fileName string, content string) error

Types

type FileIOSelector

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

FileIOSelector represents using standard file I/O.

func (*FileIOSelector) Close

func (fio *FileIOSelector) Close() error

Close is a wrapper of os.File Close.

func (*FileIOSelector) Delete

func (fio *FileIOSelector) Delete() error

Delete file descriptor if we don`t use it anymore.

func (*FileIOSelector) Read

func (fio *FileIOSelector) Read(b []byte, offset int64) (int, error)

Read is a wrapper of os.File ReadAt.

func (*FileIOSelector) Sync

func (fio *FileIOSelector) Sync() error

Sync is a wrapper of os.File Sync.

func (*FileIOSelector) Write

func (fio *FileIOSelector) Write(b []byte, offset int64) (int, error)

Write is a wrapper of os.File WriteAt.

type IOSelector

type IOSelector interface {
	// Write a slice to log file at offset.
	// It returns the number of bytes written and an error, if any.
	Write(b []byte, offset int64) (int, error)

	// Read a slice from offset.
	// It returns the number of bytes read and any error encountered.
	Read(b []byte, offset int64) (int, error)

	// Sync commits the current contents of the file to stable storage.
	// Typically, this means flushing the file system's in-memory copy
	// of recently written data to disk.
	Sync() error

	// Close closes the File, rendering it unusable for I/O.
	// It will return an error if it has already been closed.
	Close() error

	// Delete delete the file.
	// Must close it before delete, and will unmap if in MMapSelector.
	Delete() error
}

IOSelector io selector for fileio and mmap, used by wal and value log right now.

func NewFileIOSelector

func NewFileIOSelector(fName string, fsize int64) (IOSelector, error)

NewFileIOSelector create a new file io selector.

Jump to

Keyboard shortcuts

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