fs

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareFileHash

func CompareFileHash(sourcePath, expectedHash string) (bool, error)

CompareFileHash calculates a hash for a file and compares it against an expected hash

func Copy

func Copy(srcPath, destPath string) (err error)

Copy srcFile to destFile

func Download

func Download(url, downloadDir string, perms os.FileMode) (downloadedFileName string, err error)

Download pulls a file from the internet

func FilterDirectories

func FilterDirectories(_ string, info os.FileInfo) bool

FilterDirectories ignores directories in the file walk

func Glob

func Glob(pattern, realm string, matcher gitignore.Matcher, filters ...FilterFunc) (matches []string, err error)

Glob adds double-star support to the core path/filepath Glob function. It's useful when your globs might have double-stars, but you're not sure. You might recognize "**" recursive globs from things like your .gitignore file, and zsh. The "**" glob represents a recursive wildcard matching zero-or-more directory levels deep.

func GzipTar

func GzipTar(srcDir string, dest io.Writer) error

GzipTar recursively archives and compresses a given directory

func GzipTarFiles

func GzipTarFiles(files []string, prefix string, dest io.Writer, injector TarInjectorFunc) error

GzipTarFiles takes an explicit list of files and generates a gzipped tar archive to the dest io.Writer If a prefix is supplied it will trim that prefix from the file names before writing to the archive

func GzipUntar

func GzipUntar(extractDir string, r io.Reader) error

GzipUntar extracts a gzipped tar archive to the specified extraction dir

func HashDir

func HashDir(dir string, rootHash hash.Hash) (hash.Hash, error)

HashDir calculates the root hash of all files in a given directory (defaults to sha256 hash)

func HashFile

func HashFile(file string, rootHash hash.Hash) (hash.Hash, error)

HashFile calculates the sha256 of the given files contents (defaults to sha256 hash)

func NormalizePath

func NormalizePath(baseDir, path string) (string, error)

NormalizePath expands a non absolute path by resolving home directory and ensure that the path is canonical for the host OS

func NormalizePathByPrefix

func NormalizePathByPrefix(file, absBase, relBase string) (cleanFile string, err error)

NormalizePathByPrefix normalizes files with relative or absolute prefixes / will be considered absolute ./ will be normalized to the relBase // will be normalized to the relBase otherwise they will be normalized to absBase

func ReadFileBytes

func ReadFileBytes(filename string) ([]byte, error)

ReadFileBytes an alias to ioutil.ReadFIle

func ReadFileJSON

func ReadFileJSON(filename string, v interface{}) error

ReadFileJSON reads a file and unmarshalls the data into the given interface

func ReadFileString

func ReadFileString(filename string) (string, error)

ReadFileString reads a files contents as a string

func SortedFiles

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

SortedFiles aggregates all files under a specified directory and sorts lexically sorts them

func Split

func Split(path string) []string

Split splits a given file path using the os.PathSeparator

func TrimPrefix

func TrimPrefix(file string, prefix string) string

TrimPrefix trims the given prefix off a filename

func TrimPrefixAll

func TrimPrefixAll(files []string, prefix string) []string

TrimPrefixAll returns a sorted list of filenames with their prefix trimmed from the supplied list

Types

type File

type File struct {
	Name          string
	Exists        bool
	New           bool
	Type          string
	Hash          string
	SymlinkTarget string
	RelName       string
}

File a basic interface representing a file on disk

func NativeFileToSynthetic

func NativeFileToSynthetic(root, path string, info os.FileInfo) (file *File, err error)

NativeFileToSynthetic accepts a path to a file and a os.FileInfo interface and provides a pointer to an fs.File This function can return errors when attempting to resolve a symlink location and when attempting to compute the file contents current hash

func (*File) IsDir

func (f *File) IsDir() bool

IsDir returns true of the file is a directory

func (*File) IsRegular

func (f *File) IsRegular() bool

IsRegular returns true if the file is a regular file

type FilterFunc

type FilterFunc func(file string, info os.FileInfo) bool

FilterFunc should return true if a file should be retained

func FilterBySuffix

func FilterBySuffix(suffix string) FilterFunc

FilterBySuffix ignores files with the provided suffix

type TarFile

type TarFile struct {
	Name string
	Body []byte
	Mode int64
}

TarFile an in memory representation of a file for a tar archive

func (*TarFile) Header

func (t *TarFile) Header() *tar.Header

Header returns a tar file header

func (*TarFile) Size

func (t *TarFile) Size() int64

Size returns the size of the TarFIle

func (*TarFile) Write

func (t *TarFile) Write(w *tar.Writer) error

Write writes this file to a tar writer

type TarInjectorFunc

type TarInjectorFunc func(tarWriter *tar.Writer) error

TarInjectorFunc is a function used to intercept and write last minute files to a tar file

func InjectTarFiles

func InjectTarFiles(files []*TarFile) TarInjectorFunc

InjectTarFiles injects in memory files into a tar writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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