fileutil

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 8192

BlockSize is the number of bytes read into memory.

View Source
const LockExt = ".lck"

LockExt is the file extension added to file names as contents are written.

Variables

This section is empty.

Functions

func Copy

func Copy(src, dst string) error

Copy copies a file byte by byte from the src path to the dst path.

func CreateDateFuncs

func CreateDateFuncs() template.FuncMap

func FileMD5

func FileMD5(path string) (hash string, err error)

FileMD5 computes the MD5 of a file given a path.

func FindLine

func FindLine(path string, b []byte) string

FindLine searches the given file for the provided byte array and returns that line if found.

func GuessCompressed

func GuessCompressed(path string) bool

GuessCompressed attempts to determine if a file is compressed.

func HashHex

func HashHex(h hash.Hash) string

HashHex calls Sum(nil) on the input hash and formats the result in hexadecimal.

func InitPath

func InitPath(root string, path string, isdir bool) (string, error)

InitPath will turn a relative path into absolute (based on root) and make sure it exists.

func LoadJSON

func LoadJSON(path string, data interface{}) error

LoadJSON reads the file at specified path and decodes the JSON into the specified struct. The input data struct should be a pointer.

func Move

func Move(src, dst string) error

Move moves a file from one path to another. It attempts to do a rename and, if that fails, will instead do a copy followed by a deletion of the original. If the destination file already exists it will be overwritten.

func PartialMD5

func PartialMD5(path string, start int64, end int64) (hash string, err error)

PartialMD5 computes the MD5 of part of a file, specified from start byte to end byte.

func ReadableMD5

func ReadableMD5(handle sts.Readable) (hash string, err error)

ReadableMD5 computes the MD5 on a sts.Readable instance

func Readdir

func Readdir(dirname string) ([]os.FileInfo, error)

Readdir is a simple wrapper around File.Readdir that accepts a path argument as opposed to a file pointer.

func StringMD5

func StringMD5(data string) string

StringMD5 computes the MD5 hash from an array of bytes.

func Walk

func Walk(
	root string,
	walkFn filepath.WalkFunc,
	followSymLinks bool) (err error)

Walk mimics https://golang.org/pkg/path/filepath/#Walk wih the exceptions that 1) it allows for the option to follow symbolic links, and 2) the order of the calls to walkFn are NOT deterministic (i.e. no lexical ordering).

func WriteHumanJSON

func WriteHumanJSON(path string, data interface{}) (err error)

WriteHumanJSON writes the input data in a human-readable JSON format to the specified path.

func WriteJSON

func WriteJSON(path string, data interface{}) (err error)

WriteJSON writes the input data in JSON format to the specified path.

Types

type PathMap

type PathMap struct {
	Pattern   *regexp.Regexp
	Template  string
	Funcs     template.FuncMap
	ExtraVars map[string]string
	Stat      func(string) time.Time
}

PathMap houses a single translation from a pattern to a string template used to generate the mapping from an input path to an output name

func (*PathMap) Translate

func (pm *PathMap) Translate(
	inputPath string,
) (outputName string, err error)

Translate takes an input path and generates an output name if it matches the configured pattern

type PathMapper

type PathMapper struct {
	Maps   []*PathMap
	Logger sts.Logger
}

PathMapper houses an ordered list of translations for one path to another

func (*PathMapper) Translate

func (pm *PathMapper) Translate(inputPath string) string

Translate takes an input path and returns the first valid output name generated by one of the configured mappings

Jump to

Keyboard shortcuts

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