fsutil

package
v0.6.15 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 18 Imported by: 75

README

FileSystem Util

fsutil Provide some commonly file system util functions.

Install

go get github.com/gookit/goutil/fsutil

Go docs

Find files

// find all files in dir
fsutil.FindInDir("./", func(filePath string, de fs.DirEntry) error {
    fmt.Println(filePath)
    return nil
})

// find files with filters
fsutil.FindInDir("./", func(filePath string, de fs.DirEntry) error {
    fmt.Println(filePath)
    return nil
}, fsutil.ExcludeDotFile)

Functions API

Note: doc by run go doc ./fsutil

func ApplyFilters(fPath string, ent fs.DirEntry, filters []FilterFunc) bool
func CopyFile(srcPath, dstPath string) error
func CreateFile(fpath string, filePerm, dirPerm os.FileMode, fileFlag ...int) (*os.File, error)
func DeleteIfExist(fPath string) error
func DeleteIfFileExist(fPath string) error
func Dir(fpath string) string
func DiscardReader(src io.Reader)
func ExcludeDotFile(_ string, ent fs.DirEntry) bool
func Expand(pathStr string) string
func ExpandPath(pathStr string) string
func Extname(fpath string) string
func FileExists(path string) bool
func FileExt(fpath string) string
func FindInDir(dir string, handleFn HandleFunc, filters ...FilterFunc) (e error)
func GetContents(in any) []byte
func GlobWithFunc(pattern string, fn func(filePath string) error) (err error)
func IsAbsPath(aPath string) bool
func IsDir(path string) bool
func IsFile(path string) bool
func IsImageFile(path string) bool
func IsZipFile(filepath string) bool
func JoinPaths(elem ...string) string
func JoinSubPaths(basePath string, elem ...string) string
func LineScanner(in any) *bufio.Scanner
func MimeType(path string) (mime string)
func MkDirs(perm os.FileMode, dirPaths ...string) error
func MkParentDir(fpath string) error
func MkSubDirs(perm os.FileMode, parentDir string, subDirs ...string) error
func Mkdir(dirPath string, perm os.FileMode) error
func MustCopyFile(srcPath, dstPath string)
func MustCreateFile(filePath string, filePerm, dirPerm os.FileMode) *os.File
func MustReadFile(filePath string) []byte
func MustReadReader(r io.Reader) []byte
func MustRemove(fPath string)
func Name(fpath string) string
func NewIOReader(in any) (r io.Reader, err error)
func OSTempDir(pattern string) (string, error)
func OSTempFile(pattern string) (*os.File, error)
func OnlyFindDir(_ string, ent fs.DirEntry) bool
func OnlyFindFile(_ string, ent fs.DirEntry) bool
func OpenAppendFile(filepath string) (*os.File, error)
func OpenFile(filepath string, flag int, perm os.FileMode) (*os.File, error)
func OpenReadFile(filepath string) (*os.File, error)
func OpenTruncFile(filepath string) (*os.File, error)
func PathExists(path string) bool
func PathMatch(pattern, s string) bool
func PathName(fpath string) string
func PutContents(filePath string, data any, fileFlag ...int) (int, error)
func QuickOpenFile(filepath string, fileFlag ...int) (*os.File, error)
func QuietRemove(fPath string)
func ReadAll(in any) []byte
func ReadExistFile(filePath string) []byte
func ReadFile(filePath string) []byte
func ReadOrErr(in any) ([]byte, error)
func ReadReader(r io.Reader) []byte
func ReadString(in any) string
func ReadStringOrErr(in any) (string, error)
func ReaderMimeType(r io.Reader) (mime string)
func Realpath(pathStr string) string
func Remove(fPath string) error
func ResolvePath(pathStr string) string
func RmFileIfExist(fPath string) error
func RmIfExist(fPath string) error
func SearchNameUp(dirPath, name string) string
func SearchNameUpx(dirPath, name string) (string, bool)
func SlashPath(path string) string
func SplitPath(pathStr string) (dir, name string)
func Suffix(fpath string) string
func TempDir(dir, pattern string) (string, error)
func TempFile(dir, pattern string) (*os.File, error)
func TextScanner(in any) *scanner.Scanner
func ToAbsPath(p string) string
func UnixPath(path string) string
func Unzip(archive, targetDir string) (err error)
func WalkDir(dir string, fn fs.WalkDirFunc) error
func WriteFile(filePath string, data any, perm os.FileMode, fileFlag ...int) error
func WriteOSFile(f *os.File, data any) (n int, err error)
type FilterFunc func(fPath string, ent fs.DirEntry) bool
func ExcludeSuffix(ss ...string) FilterFunc
func IncludeSuffix(ss ...string) FilterFunc
type HandleFunc func(fPath string, ent fs.DirEntry) error

Code Check & Testing

gofmt -w -l ./
golint ./...

Testing:

go test -v ./fsutil/...

Test limit by regexp:

go test -v -run ^TestSetByKeys ./fsutil/...

Documentation

Overview

Package fsutil Filesystem util functions, quick create, read and write file. eg: file and dir check, operate

Index

Constants

View Source
const (
	FsCWAFlags = os.O_CREATE | os.O_WRONLY | os.O_APPEND // create, append write-only
	FsCWTFlags = os.O_CREATE | os.O_WRONLY | os.O_TRUNC  // create, override write-only
	FsCWFlags  = os.O_CREATE | os.O_WRONLY               // create, write-only
	FsRWFlags  = os.O_RDWR                               // read-write, dont create.
	FsRFlags   = os.O_RDONLY                             // read-only
)

some commonly flag consts for open file.

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

Variables

View Source
var (
	DefaultDirPerm   os.FileMode = 0775
	DefaultFilePerm  os.FileMode = 0665
	OnlyReadFilePerm os.FileMode = 0444
)

perm for create dir or file

View Source
var (
	// DefaultFileFlags for create and write
	DefaultFileFlags = os.O_CREATE | os.O_WRONLY | os.O_APPEND
	// OnlyReadFileFlags open file for read
	OnlyReadFileFlags = os.O_RDONLY
)
View Source
var (
	DirExist  = IsDir
	FileExist = IsFile
	PathExist = PathExists
)

alias methods

View Source
var (
	// MustRm removes the named file or (empty) directory.
	MustRm = MustRemove
	// QuietRm removes the named file or (empty) directory.
	QuietRm = QuietRemove
)

alias methods

View Source
var ImageMimeTypes = map[string]string{
	"bmp": "image/bmp",
	"gif": "image/gif",
	"ief": "image/ief",
	"jpg": "image/jpeg",

	"jpeg": "image/jpeg",
	"png":  "image/png",
	"svg":  "image/svg+xml",
	"ico":  "image/x-icon",
	"webp": "image/webp",
}

ImageMimeTypes refer net/http package

Functions

func ApplyFilters added in v0.6.8

func ApplyFilters(fPath string, ent fs.DirEntry, filters []FilterFunc) bool

ApplyFilters handle

func CopyFile added in v0.3.8

func CopyFile(srcPath, dstPath string) error

CopyFile copy a file to another file path.

func CreateFile added in v0.2.10

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

CreateFile create file if not exists

Usage:

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

func DeleteIfExist added in v0.3.11

func DeleteIfExist(fPath string) error

DeleteIfExist removes the named file or (empty) directory on exists.

func DeleteIfFileExist added in v0.2.10

func DeleteIfFileExist(fPath string) error

DeleteIfFileExist removes the named file on exists.

func DetectMime added in v0.6.11

func DetectMime(path string) string

DetectMime detect file mime type. alias of MimeType()

func Dir added in v0.3.10

func Dir(fpath string) string

Dir get dir path from filepath, without last name.

func DirPath added in v0.6.11

func DirPath(fpath string) string

DirPath get dir path from filepath, without last name.

func DiscardReader added in v0.4.5

func DiscardReader(src io.Reader)

DiscardReader anything from the reader

func ExcludeDotFile added in v0.6.8

func ExcludeDotFile(_ string, ent fs.DirEntry) bool

ExcludeDotFile on find

func Expand added in v0.5.3

func Expand(pathStr string) string

Expand will parse first `~` as user home dir path.

func ExpandPath added in v0.3.9

func ExpandPath(pathStr string) string

ExpandPath will parse `~` as user home dir path.

func Extname added in v0.6.6

func Extname(fpath string) string

Extname get filename ext. alias of path.Ext()

eg: path/to/main.go => "go"

func FileExists

func FileExists(path string) bool

FileExists reports whether the named file or directory exists.

func FileExt added in v0.3.8

func FileExt(fpath string) string

FileExt get filename ext. alias of path.Ext()

eg: path/to/main.go => ".go"

func FilePathInDirs added in v0.6.13

func FilePathInDirs(file string, dirs ...string) string

FilePathInDirs get full file path in dirs.

Params:

  • file: can be relative path, file name, full path.
  • dirs: dir paths

func FindInDir added in v0.5.3

func FindInDir(dir string, handleFn HandleFunc, filters ...FilterFunc) (e error)

FindInDir code refer the go pkg: path/filepath.glob()

- TIP: will be not find in subdir.

filters: return false will skip the file.

func FirstExists added in v0.6.11

func FirstExists(paths ...string) string

FirstExists check multi paths and return first exists path.

func FirstExistsDir added in v0.6.11

func FirstExistsDir(paths ...string) string

FirstExistsDir check multi paths and return first exists dir.

func FirstExistsFile added in v0.6.11

func FirstExistsFile(paths ...string) string

FirstExistsFile check multi paths and return first exists file.

func GetContents added in v0.5.3

func GetContents(in any) []byte

GetContents read contents from path or io.Reader, will panic on in type error

func Glob added in v0.6.10

func Glob(pattern string, fls ...NameMatchFunc) []string

Glob find files by glob path pattern. alias of filepath.Glob() and support filter matched files by name.

Usage:

files := fsutil.Glob("/path/to/dir/*.go")

func GlobWithFunc added in v0.5.2

func GlobWithFunc(pattern string, fn func(filePath string) error) (err error)

GlobWithFunc find files by glob path pattern, then handle matched file

- TIP: will be not find in subdir.

func IsAbsPath

func IsAbsPath(aPath 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 IsEmptyDir added in v0.6.12

func IsEmptyDir(dirPath string) bool

IsEmptyDir reports whether the named directory is empty.

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 JoinPaths added in v0.6.2

func JoinPaths(elem ...string) string

JoinPaths elements, alias of filepath.Join()

func JoinSubPaths added in v0.6.8

func JoinSubPaths(basePath string, elem ...string) string

JoinSubPaths elements, like the filepath.Join()

func LineScanner added in v0.6.2

func LineScanner(in any) *bufio.Scanner

LineScanner create from filepath or io.Reader, will panic on in type error. Will scan and parse text to lines.

s := fsutil.LineScanner("/path/to/file")
for s.Scan() {
	fmt.Println(s.Text())
}

func MatchFirst added in v0.6.11

func MatchFirst(paths []string, matcher PathMatchFunc, defaultPath string) string

MatchFirst filter paths by filter func and return first match path.

func MatchPaths added in v0.6.11

func MatchPaths(paths []string, matcher PathMatchFunc) []string

MatchPaths given paths by custom mather func.

func MimeType added in v0.2.5

func MimeType(path string) (mime string)

MimeType get file mime type name. eg "image/png"

func MkDirs added in v0.6.2

func MkDirs(perm os.FileMode, dirPaths ...string) error

MkDirs batch make multi dirs at once

func MkParentDir added in v0.3.11

func MkParentDir(fpath string) error

MkParentDir quick create parent dir for given path.

func MkSubDirs added in v0.6.2

func MkSubDirs(perm os.FileMode, parentDir string, subDirs ...string) error

MkSubDirs batch make multi sub-dirs at once

func Mkdir added in v0.2.2

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

Mkdir alias of os.MkdirAll()

func MustCopyFile added in v0.3.8

func MustCopyFile(srcPath, dstPath string)

MustCopyFile copy file to another path.

func MustCreateFile added in v0.3.8

func MustCreateFile(filePath string, filePerm, dirPerm os.FileMode) *os.File

MustCreateFile create file, will panic on error

func MustOpenFile added in v0.6.9

func MustOpenFile(filePath string, flag int, perm os.FileMode) *os.File

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

Usage:

file := MustOpenFile("path/to/file.txt", FsCWFlags, 0666)

func MustRead added in v0.6.11

func MustRead(in any) []byte

MustRead read contents from path or io.Reader, will panic on in type error

func MustReadFile added in v0.3.7

func MustReadFile(filePath string) []byte

MustReadFile read file contents, will panic on error

func MustReadReader added in v0.4.3

func MustReadReader(r io.Reader) []byte

MustReadReader read contents from io.Reader, will panic on error

func MustRemove added in v0.3.11

func MustRemove(fPath string)

MustRemove removes the named file or (empty) directory. NOTICE: will panic on error

func MustSave added in v0.6.11

func MustSave(filePath string, data any, optFns ...OpenOptionFunc)

MustSave create file and write contents to file, panic on error.

  • data type allow: string, []byte, io.Reader

default option see NewOpenOption()

func Name added in v0.3.10

func Name(fpath string) string

Name get file/dir name from full path.

eg: path/to/main.go => main.go

func NewIOReader added in v0.6.2

func NewIOReader(in any) (r io.Reader, err error)

NewIOReader instance by input file path or io.Reader

func OSTempDir added in v0.3.12

func OSTempDir(pattern string) (string, error)

OSTempDir creates a new temp dir on os.TempDir and return the temp dir path

Usage:

fsutil.OSTempDir("example.*")

func OSTempFile added in v0.3.12

func OSTempFile(pattern string) (*os.File, error)

OSTempFile create a temp file on os.TempDir()

Usage:

fsutil.OSTempFile("example.*.txt")

func OnlyFindDir added in v0.6.8

func OnlyFindDir(_ string, ent fs.DirEntry) bool

OnlyFindDir on find

func OnlyFindFile added in v0.6.8

func OnlyFindFile(_ string, ent fs.DirEntry) bool

OnlyFindFile on find

func OpenAppendFile added in v0.6.7

func OpenAppendFile(filepath string, filePerm ...os.FileMode) (*os.File, error)

OpenAppendFile like os.OpenFile, open for append write. if not exists, will create it.

func OpenFile added in v0.3.7

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

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

Usage:

file, err := OpenFile("path/to/file.txt", FsCWFlags, 0666)

func OpenReadFile added in v0.5.3

func OpenReadFile(filepath string) (*os.File, error)

OpenReadFile like os.OpenFile, open file for read contents

func OpenTruncFile added in v0.6.7

func OpenTruncFile(filepath string, filePerm ...os.FileMode) (*os.File, error)

OpenTruncFile like os.OpenFile, open for override write. if not exists, will create it.

func PathExists added in v0.2.1

func PathExists(path string) bool

PathExists reports whether the named file or directory exists.

func PathMatch added in v0.6.8

func PathMatch(pattern, s string) bool

PathMatch check for a string. alias of path.Match()

func PathName added in v0.5.0

func PathName(fpath string) string

PathName get file/dir name from full path

func PutContents added in v0.5.3

func PutContents(filePath string, data any, fileFlag ...int) (int, error)

PutContents create file and write contents to file at once.

data type allow: string, []byte, io.Reader. will auto create dir.

Tip: file flag default is FsCWTFlags (override write)

Usage:

fsutil.PutContents(filePath, contents, fsutil.FsCWAFlags) // append write

func QuickOpenFile added in v0.3.8

func QuickOpenFile(filepath string, fileFlag ...int) (*os.File, error)

QuickOpenFile like os.OpenFile, open for append write. if not exists, will create it.

Alias of OpenAppendFile()

func QuietRemove added in v0.3.11

func QuietRemove(fPath string)

QuietRemove removes the named file or (empty) directory.

NOTICE: will ignore error

func ReadAll added in v0.6.3

func ReadAll(in any) []byte

ReadAll read contents from path or io.Reader, will panic on in type error

func ReadExistFile added in v0.3.11

func ReadExistFile(filePath string) []byte

ReadExistFile read file contents if existed, will panic on error

func ReadFile added in v0.6.3

func ReadFile(filePath string) []byte

ReadFile read file contents, will panic on error

func ReadOrErr added in v0.6.9

func ReadOrErr(in any) ([]byte, error)

ReadOrErr read contents from path or io.Reader, will panic on in type error

func ReadReader added in v0.6.3

func ReadReader(r io.Reader) []byte

ReadReader read contents from io.Reader, will panic on error

func ReadString added in v0.6.2

func ReadString(in any) string

ReadString read contents from path or io.Reader, will panic on in type error

func ReadStringOrErr added in v0.6.9

func ReadStringOrErr(in any) (string, error)

ReadStringOrErr read contents from path or io.Reader, will panic on in type error

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 Realpath added in v0.4.0

func Realpath(pathStr string) string

Realpath returns the shortest path name equivalent to path by purely lexical processing. Will expand ~ to home dir, and join with workdir if path is relative path.

func Remove added in v0.5.0

func Remove(fPath string) error

Remove removes the named file or (empty) directory.

func RemoveSub added in v0.6.9

func RemoveSub(dirPath string, fns ...FilterFunc) error

RemoveSub removes all sub files and dirs of dirPath, but not remove dirPath.

func ResolvePath added in v0.6.8

func ResolvePath(pathStr string) string

ResolvePath will parse `~` and env var in path

func RmFileIfExist added in v0.5.3

func RmFileIfExist(fPath string) error

RmFileIfExist removes the named file on exists.

func RmIfExist added in v0.5.3

func RmIfExist(fPath string) error

RmIfExist removes the named file or (empty) directory on exists.

func SafeRemoveAll added in v0.6.11

func SafeRemoveAll(path string)

SafeRemoveAll removes path and any children it contains. will ignore error

func SaveFile added in v0.6.11

func SaveFile(filePath string, data any, optFns ...OpenOptionFunc) error

SaveFile create file and write contents to file. will auto create dir.

  • data type allow: string, []byte, io.Reader

default option see NewOpenOption()

func SearchNameUp added in v0.6.8

func SearchNameUp(dirPath, name string) string

SearchNameUp find file/dir name in dirPath or parent dirs, return the name of directory path

Usage:

repoDir := fsutil.SearchNameUp("/path/to/dir", ".git")

func SearchNameUpx added in v0.6.8

func SearchNameUpx(dirPath, name string) (string, bool)

SearchNameUpx find file/dir name in dirPath or parent dirs, return the name of directory path and dir is changed.

func SlashPath added in v0.6.7

func SlashPath(path string) string

SlashPath alias of filepath.ToSlash

func SplitPath added in v0.5.6

func SplitPath(pathStr string) (dir, name string)

SplitPath splits path immediately following the final Separator, separating it into a directory and file name component

func Suffix added in v0.3.8

func Suffix(fpath string) string

Suffix get filename ext. alias of path.Ext()

eg: path/to/main.go => ".go"

func TempDir added in v0.3.12

func TempDir(dir, pattern string) (string, error)

TempDir creates a new temp dir and return the temp dir path

Usage:

fsutil.TempDir("", "example.*")
fsutil.TempDir("testdata", "example.*")

func TempFile added in v0.3.12

func TempFile(dir, pattern string) (*os.File, error)

TempFile is like os.CreateTemp, but can custom temp dir.

Usage:

// create temp file on os.TempDir()
fsutil.TempFile("", "example.*.txt")
// create temp file on "testdata" dir
fsutil.TempFile("testdata", "example.*.txt")

func TextScanner added in v0.6.2

func TextScanner(in any) *scanner.Scanner

TextScanner from filepath or io.Reader, will panic on in type error. Will scan parse text to tokens: Ident, Int, Float, Char, String, RawString, Comment, etc.

Usage:

s := fsutil.TextScanner("/path/to/file")
for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() {
	fmt.Printf("%s: %s\n", s.Position, s.TokenText())
}

func ToAbsPath added in v0.6.8

func ToAbsPath(p string) string

ToAbsPath convert process. will expand home dir

TIP: will don't check path

func UnixPath added in v0.6.7

func UnixPath(path string) string

UnixPath like of filepath.ToSlash, but always replace

func Unzip

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

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

func UpdateContents added in v0.6.12

func UpdateContents(filePath string, handleFn func(bs []byte) []byte) error

UpdateContents read file contents, call handleFn(contents) handle, then write updated contents to file

func WalkDir added in v0.6.8

func WalkDir(dir string, fn fs.WalkDirFunc) error

WalkDir walks the file tree rooted at root, calling fn for each file or directory in the tree, including root.

TIP: will recursively find in sub dirs.

func WriteFile added in v0.5.8

func WriteFile(filePath string, data any, perm os.FileMode, fileFlag ...int) error

WriteFile create file and write contents to file, can set perm for file.

data type allow: string, []byte, io.Reader

Tip: file flag default is FsCWTFlags (override write)

Usage:

fsutil.WriteFile(filePath, contents, fsutil.DefaultFilePerm, fsutil.FsCWAFlags)

func WriteOSFile added in v0.6.2

func WriteOSFile(f *os.File, data any) (n int, err error)

WriteOSFile write data to give os.File, then close file.

data type allow: string, []byte, io.Reader

Types

type Entry added in v0.6.11

type Entry interface {
	fs.DirEntry
	// Path get file/dir full path. eg: "/path/to/file.go"
	Path() string
	// Info get file info. like fs.DirEntry.Info(), but will cache result.
	Info() (fs.FileInfo, error)
}

Entry extends fs.DirEntry, add some useful methods

func NewEntry added in v0.6.11

func NewEntry(fPath string, ent fs.DirEntry) Entry

NewEntry create a new Entry instance

type FileInfo added in v0.6.11

type FileInfo interface {
	fs.FileInfo
	// Path get file full path. eg: "/path/to/file.go"
	Path() string
}

FileInfo extends fs.FileInfo, add some useful methods

func NewFileInfo added in v0.6.11

func NewFileInfo(fPath string, info fs.FileInfo) FileInfo

NewFileInfo create a new FileInfo instance

type FileInfos added in v0.6.11

type FileInfos []FileInfo

FileInfos type for FileInfo slice

implements sort.Interface:

sorts by oldest time modified in the file info.
eg: [old_220211, old_220212, old_220213]

func (FileInfos) Len added in v0.6.11

func (fis FileInfos) Len() int

Len get length

func (FileInfos) Less added in v0.6.11

func (fis FileInfos) Less(i, j int) bool

Less check by mod time

func (FileInfos) Swap added in v0.6.11

func (fis FileInfos) Swap(i, j int)

Swap swap values

type FilterFunc added in v0.3.8

type FilterFunc func(fPath string, ent fs.DirEntry) bool

FilterFunc type for FindInDir

- return False will skip handle the file.

func ExcludeNames added in v0.6.9

func ExcludeNames(names ...string) FilterFunc

ExcludeNames on find

func ExcludeSuffix added in v0.6.8

func ExcludeSuffix(ss ...string) FilterFunc

ExcludeSuffix on find

func IncludeSuffix added in v0.6.8

func IncludeSuffix(ss ...string) FilterFunc

IncludeSuffix on find

type HandleFunc added in v0.5.3

type HandleFunc func(fPath string, ent fs.DirEntry) error

HandleFunc type for FindInDir

type NameMatchFunc added in v0.6.11

type NameMatchFunc = comdef.StringMatchFunc

NameMatchFunc name match func, alias of comdef.StringMatchFunc

type OpenOption added in v0.6.11

type OpenOption struct {
	// file open flag. see FsCWTFlags
	Flag int
	// file perm. see DefaultFilePerm
	Perm os.FileMode
}

OpenOption for open file

func NewOpenOption added in v0.6.11

func NewOpenOption(optFns ...OpenOptionFunc) *OpenOption

NewOpenOption create a new OpenOption instance

Defaults:

  • open flags: FsCWTFlags (override write)
  • file Perm: DefaultFilePerm

func OpenOptOrNew added in v0.6.11

func OpenOptOrNew(opt *OpenOption) *OpenOption

OpenOptOrNew create a new OpenOption instance if opt is nil

type OpenOptionFunc added in v0.6.11

type OpenOptionFunc func(*OpenOption)

OpenOptionFunc for open/write file

func WithFlag added in v0.6.11

func WithFlag(flag int) OpenOptionFunc

WithFlag set file open flag

func WithPerm added in v0.6.11

func WithPerm(perm os.FileMode) OpenOptionFunc

WithPerm set file perm

type PathMatchFunc added in v0.6.11

type PathMatchFunc = comdef.StringMatchFunc

PathMatchFunc path match func. alias of comdef.StringMatchFunc

Directories

Path Synopsis
Package finder Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc.
Package finder Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc.

Jump to

Keyboard shortcuts

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