osutil

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

OS Uiliities.

Index

Constants

View Source
const (
	// Default File Mode
	DefFileMode = 0666

	GbUnit uint64 = MbUnit * 1024
	MbUnit uint64 = KbUnit * 1024
	KbUnit uint64 = 1024
)

Variables

This section is empty.

Functions

func FileAddSuffix

func FileAddSuffix(name string, ext string) string

func FileChangeSuffix

func FileChangeSuffix(name string, newSuffix string) (s string)

func FileCutDotSuffix

func FileCutDotSuffix(name string) (s string, suffix string, ok bool)

func FileCutSuffix

func FileCutSuffix(name string, ext string) (string, bool)

func FileExists

func FileExists(path string) (bool, error)

Check if file exists

func FileHasAnySuffix

func FileHasAnySuffix(name string, ext ...string) bool

func FileHasSuffix

func FileHasSuffix(name string, ext string) bool

func FileReplaceSuffix

func FileReplaceSuffix(name string, ext string) string

func MkdirAll

func MkdirAll(path string) error

MkdirAll with 0755 perm.

func MkdirParentAll

func MkdirParentAll(path string) error

MkdirAll but only for the parent directory of the path, perm 0755 is used.

The path should always point to a specific file under some directories, as this method always attempts to extract parent dir of the file. It the path fails to fulfill this requirement, the output might be unexpected.

func MkdirTree

func MkdirTree(t DirTree) error

func NewTmpFile

func NewTmpFile() (*os.File, error)

func NewTmpFilePath

func NewTmpFilePath() (string, error)

func NewTmpFilePathWith

func NewTmpFilePathWith(suffix string) (string, error)

func NewTmpFileWith

func NewTmpFileWith(suffix string) (*os.File, error)

func OpenAppendFile

func OpenAppendFile(name string) (*os.File, error)

Create appendable file with 0666 permission.

func OpenFile

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

Open file with 0666 permission.

func OpenRFile

func OpenRFile(name string) (*os.File, error)

Open readable file with 0666 permission.

func OpenRWFile

func OpenRWFile(name string, createIfAbsent ...bool) (*os.File, error)

Open readable & writable file with 0666 permission.

By default createIfAbsent is true.

func ReadFileAll

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

Read all content from file.

func SaveTmpFile

func SaveTmpFile(tmpDir string, reader io.Reader) (string, error)

Save to temp file, returns temp file path or error.

func TryFileExists

func TryFileExists(path string) bool

Check if file exists without returning error.

This is mainly a lazy version of FileExists(), it's not recommended for most cases.

func WriteFile added in v0.4.12

func WriteFile(name string, content []byte) error

Create file and write content.

func WriteFileStr added in v0.4.12

func WriteFileStr(name string, content string) error

Create file and write content.

Types

type DirTree

type DirTree struct {
	Name      string
	Childs    []DirTree
	IsFile    bool
	OnCreated func(f *os.File) error
	Skip      bool
}

type WalkFsFile

type WalkFsFile struct {
	Path string
	File fs.FileInfo
}

func WalkDir

func WalkDir(n string, suffix ...string) ([]WalkFsFile, error)

Jump to

Keyboard shortcuts

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