package fileutil

import "github.com/tredoe/osutil/fileutil"

Package fileutil handles common operations in files.

Index

Constants

const (
	R perm // read
	W      // write
	X      // execute
)

permissions

Variables

var (

	// ErrNotFound indicates when a search does not find a file at 'LookPath()'.
	ErrNotFound = errors.New("file not found")
)

Functions

func CheckDir

func CheckDir(p string) error

CheckDir checks if the path exists and if it is a directory.

func CheckFile

func CheckFile(p string) error

CheckFile checks if the path exists and if it is a file.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from 'src' to 'dst'. If 'src' and 'dst' files exist, and are the same, then return success. Otherwise, copy the file contents from 'src' to 'dst'.

The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file.

func CopytoTemp

func CopytoTemp(filename string) (tmpFile string, err error)

CopytoTemp copies a file from the filename to the default directory with temporary files (see os.TempDir). Returns the temporary file name.

func Create

func Create(filename string, b []byte) (err error)

Create creates a new file with b bytes. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask).

func CreateDir

func CreateDir(dir string) error

CreateDir creates a directory if it does not exist.

func CreateFromString

func CreateFromString(filename string, s string) error

CreateFromString creates a new file with the string 's'.

func Dload

func Dload(urlFile string, dst io.Writer) error

Dload downloads a file.

func GroupHas

func GroupHas(name string, p ...perm) (bool, error)

GroupHas reports whether the named file has all given permissions for the group.

func IsDir

func IsDir(name string) (bool, error)

IsDir reports whether if the named file is a directory.

func IsFile

func IsFile(name string) (bool, error)

IsFile reports whether the named file is a regular file.

func LastDirNumeric

func LastDirNumeric(path string) (fullPath string, version string, err error)

LastDirNumeric returns the last directory based at numbers.

func LookDirExec

func LookDirExec(syst osutil.System, filename string) (string, error)

LookDirExec looks up the directory of an executable.

func LookPath

func LookPath(syst osutil.System, filename ...string) (string, error)

LookPath searches for an executable named file in the system directories given one or several executables.

func OthersHave

func OthersHave(name string, p ...perm) (bool, error)

OthersHave reports whether the named file have all given permissions for the others.

func Overwrite

func Overwrite(filename string, b []byte) (err error)

Overwrite truncates the named file to zero and writes len(b) bytes. It is created with mode 0666 (before umask).

func OwnerHas

func OwnerHas(name string, p ...perm) (bool, error)

OwnerHas reports whether the named file has all given permissions for the owner.

func PathAbsDir

func PathAbsDir(dir string) (string, error)

PathAbsDir returns the absolute path of a directory.

func PathRelative

func PathRelative(dir, file string) string

PathRelative returns the relative path of a file.

func ReadGob

func ReadGob(filePath string, x interface{}) (err error)

ReadGob gets data from a Go binary value.

func Untar

func Untar(filename, dirDst string) error

Untar uncompresses a 'tar.gz' or 'tar' file.

func WriteGob

func WriteGob(filePath string, x interface{}) (err error)

WriteGob exports data to a Go binary value.

func WritetoTemp

func WritetoTemp(b []byte, name string) (filename string, err error)

WritetoTemp writes bytes to a temporary file and returns its name.

Types

type Info

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

Info represents a wrapper about os.FileInfo to append some functions.

func NewInfo

func NewInfo(name string) (Info, error)

NewInfo returns a Info describing the named file.

func (Info) GroupHas

func (i Info) GroupHas(p ...perm) bool

GroupHas reports whether the group has all given permissions.

func (Info) IsDir

func (i Info) IsDir() bool

IsDir reports whether if it is a directory.

func (Info) IsFile

func (i Info) IsFile() bool

IsFile reports whether it is a regular file.

func (Info) OthersHave

func (i Info) OthersHave(p ...perm) bool

OthersHave reports whether the others have all given permissions.

func (Info) OwnerHas

func (i Info) OwnerHas(p ...perm) bool

OwnerHas reports whether the owner has all given permissions.

Source Files

compress.go dir.go doc.go encoding.go file.go http.go info.go io.go path.go

Version
v1.3.1
Published
Aug 16, 2021
Platform
js/wasm
Imports
15 packages
Last checked
1 day ago

Tools for package owners.