fsutil

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 8 Imported by: 110

Documentation

Index

Constants

View Source
const (
	// sniff Length, use for detect file mime type
	MimeSniffLen = 512
)

Variables

View Source
var (
	// perm and flags for create log file
	DefaultDirPerm  os.FileMode = 0665
	DefaultFilePerm os.FileMode = 0665

	DefaultFileFlags = os.O_CREATE | os.O_WRONLY | os.O_APPEND
)

Functions

func CreateFile added in v0.2.10

func CreateFile(fpath string, filePerm, dirPerm os.FileMode) (*os.File, error)

CreateFile if not exists Usage:

CreateFile("path/to/file.txt", 0664, 0666)

func DeleteIfFileExist added in v0.2.10

func DeleteIfFileExist(fpath string) error

DeleteIfFileExist operate

func FileExists

func FileExists(path string) bool

FileExists reports whether the named file or directory exists.

func IsAbsPath

func IsAbsPath(filepath string) bool

IsAbsPath is abs path.

func IsDir added in v0.2.1

func IsDir(path string) bool

IsDir reports whether the named directory exists.

func IsFile added in v0.2.1

func IsFile(path string) bool

IsFile reports whether the named file or directory exists.

func IsImageFile added in v0.2.5

func IsImageFile(path string) bool

IsImageFile check file is image file.

func IsZipFile

func IsZipFile(filepath string) bool

IsZipFile check is zip file. from https://blog.csdn.net/wangshubo1989/article/details/71743374

func MimeType added in v0.2.5

func MimeType(path string) (mime string)

MimeType get File Mime Type name. eg "image/png"

func Mkdir added in v0.2.2

func Mkdir(dirPath string, perm os.FileMode) error

Mkdir alias of os.MkdirAll()

func MustReadFile added in v0.3.7

func MustReadFile(filePath string) []byte

MustReadFile read file contents, will panic on error

func OpenFile added in v0.3.7

func OpenFile(filepath string, flag int, perm int) (*os.File, error)

OpenFile like os.OpenFile, but will auto create dir.

func PathExists added in v0.2.1

func PathExists(path string) bool

PathExists reports whether the named file or directory exists.

func ReaderMimeType added in v0.2.5

func ReaderMimeType(r io.Reader) (mime string)

ReaderMimeType get the io.Reader mimeType Usage:

file, err := os.Open(filepath)
if err != nil {
	return
}
mime := ReaderMimeType(file)

func Unzip

func Unzip(archive, targetDir string) (err error)

Unzip a zip archive from https://blog.csdn.net/wangshubo1989/article/details/71743374

Types

type FileFinder added in v0.3.7

type FileFinder struct {
}

FileFinder

Jump to

Keyboard shortcuts

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