fsutil

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MPL-2.0 Imports: 10 Imported by: 4

README

fsutil

fs utils in golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileExists = errors.New("file exists")
)

Functions

func AllSubfolders

func AllSubfolders(dir string) ([]string, error)

AllSubfolders gets all subfolders under given dir. Hidden folders are ignored.

func CreateFile

func CreateFile(fp string, force bool) error

CreateFile create a new file with given path. If directory does not exist, return error. If force is true, will truncate existing one. Otherwise, will throw FileExist error.

func CreateFileRecursively

func CreateFileRecursively(fp string) (*os.File, error)

CreateFileRecursively - create file anyway, if file exists, empty it and return.

func EnsureDir

func EnsureDir(path string) error

EnsureDir will check whether directory exists. If not, create the directory.

func ExcludeExt

func ExcludeExt(filename string) string

ExcludeExt returns filename without extension

func Exists

func Exists(path string) (bool, error)

Exists returns whether the given file or directory exists or not.

func FileSync

func FileSync(fp string, content []byte) error

blocking call

func IsDir

func IsDir(path string) bool

IsDir checks whether the given path is a directory.

func IsEmpty

func IsEmpty(path string) (bool, error)

IsEmpty tests whether the file size is empty. Always returns true if not exist.

func IsFile

func IsFile(path string) bool

IsFile checks whether the given path is a regular file

func IsHiddenFile

func IsHiddenFile(f os.FileInfo) bool

IsHiddenFile checks whether the file is hidden, that's, starts with ".".

func IsSymlink(path string) bool

IsSymlink checks whether the given path is a regular file

func ProcessLine

func ProcessLine(r io.Reader, handler func(line string) bool) error

ProcessLine reads the lines from reader and apply each line to handler. If handler returns false, stop consuming remaining lines. NOTE: Max allowed line size is 2M bytes. https://devmarkpro.com/working-big-files-golang

func SimpleExists

func SimpleExists(path string) bool

SimpleExists reports whether the given path exists.

func WriteFile

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

WriteFile writes content to file. If file exists, truncate it first.

func WriteToFile

func WriteToFile(fp string, content []byte) error

Types

type FileSyncReq

type FileSyncReq struct {
	Content  []byte
	Filepath string
	Result   chan error
}

FileSyncer writes bytes to file. using only one goroutine for performance.

type FileSyncer

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

func NewFileSyncer

func NewFileSyncer(capacity int) *FileSyncer

Jump to

Keyboard shortcuts

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