fileutil

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

FileUtil

Package fileutil handles common operations in files.

Documentation online

Author

Jonás Melián (https://bitbucket.org/ares)

License

The source files are distributed under the Apache License, version 2.0.

Documentation

Overview

Package fileutil handles common operations in files.

During tests, can be used the next tags:

-tags=log

	Run tests with logging.

Index

Constants

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

Permissions

Variables

Log is the logger by default.

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(dst io.Writer, fileURL string) error

Dload downloads a file and returns the file name of the URL.

func DloadToFile

func DloadToFile(dir, fileURL string) error

DloadToFile downloads a file and saves it into directory 'dir'.

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

Jump to

Keyboard shortcuts

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