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

const PrefixTemp = "tmp-"

PrefixTemp is the prefix to add to temporary files.

Variables

var (

	// ErrNotFound indicates when a search does not find a file at 'LookPath()'.
	ErrNotFound = errors.New("file not found")
)
var Log = log.New(io.Discard, "", -1)

Logger is the global logger. By default, it does not write logs.

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 Create

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

Create creates a new file with b bytes.

func CreateDir

func CreateDir(dir string) error

CreateDir creates a directory if it does not exist.

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 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.

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 TempFile

func TempFile(src, prefix string) (tmpFile string, err error)

TempFile creates a temporary file from the source file into the default directory temporary files (see os.TempDir), whose name begins with the prefix. If prefix is the empty string, uses the default value PrefixTemp. Returns the temporary file name.

func Untar

func Untar(filename, dirDst string) error

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

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 file.go http.go info.go io.go log.go path.go

Version
v1.1.1
Published
Aug 1, 2021
Platform
js/wasm
Imports
14 packages
Last checked
1 day ago

Tools for package owners.