fileutil

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: MIT Imports: 8 Imported by: 2

README

fileutil

Provides utilities for interacting with files on the filesystem, such as determining if a file is Binary or a Symlink.

IsBinaryFile

Attempts to determine if the provided file is Binary by reading pieces of it from the filesystem.

Determines if the file is a Symlink

IsDir

Determines if the file is a directory or regular file.

DirToArray

Collapses a directory tree into a slice of files, including the full path to the file. File filters and Directory filters can be supplied to limit the results, such as file filters that remove Binary or Symlink files from the results. The default file filter exclused symlinks and binary files, and the default directory filter excludes a .git directory. These can be supplied to fit your needs.

files := fileutil.DirToArray(dir, false, fileutil.SymlinkFileFilter, fileutil.DefaultDirectoryFilter)

FilterExtBlacklist

FilterExtBlacklist takes a list of extensions and a slice of files and removes any files in that list that have an extension matching an item in the blacklist.

FilterExtWhitelist

FilterExtWhitelist takes a list of extensions and a slice of files and removes any files in that list that do not have an extension matching an item in the whitelist.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryFileFilter

func BinaryFileFilter(path, fileName string) bool

BinaryFileFilter excludes binary files.

func DefaultDirectoryFilter

func DefaultDirectoryFilter(path, dirName string) bool

DefaultDirectoryFilter returns true if the file should be kept, false if it should be discarded.

func DefaultFileFilter

func DefaultFileFilter(path, fileName string) bool

DefaultFileFilter excludes symlinks and binary files.

func DirToArray

func DirToArray(dir string, followSyms bool, fileFilter func(string, string) bool, dirFilter func(string, string) bool) []string

DirToArray will flatten a directory into a simple list of files that can be iterated over.

func FilterExtBlacklist

func FilterExtBlacklist(ext, files []string) []string

FilterExtBlacklist removes any files where the extension is found in the extension list.

func FilterExtWhitelist

func FilterExtWhitelist(ext, files []string) []string

FilterExtWhitelist removes any files where the extension is not found in the extension list.

func FilterOutBinaries

func FilterOutBinaries(files []string) []string

FilterOutBinaries removes any binary files from the given file list.

func FilterOutSymlinks(files []string) []string

FilterOutSymlinks removes any symlink files from the given file list.

func IsBinaryData

func IsBinaryData(b []byte) bool

IsBinaryData attemtpts to determine whether a given byte slice contains binary data.

func IsBinaryFile

func IsBinaryFile(fileName string) bool

IsBinaryFile attemtpts to determine whether a file is a binary file.

func IsDir

func IsDir(fileName string) bool

IsDir will return true only if the given path exists and is a directory.

func IsFile

func IsFile(fileName string) bool

IsFile will return true only if the given path exists and is a regular file.

func IsSymlink(fileName string) bool

IsSymlink returns if a given file is a symlink, False otherwise.

func SymlinkFileFilter

func SymlinkFileFilter(path, fileName string) bool

SymlinkFileFilter excludes symlinks and binary files.

Types

This section is empty.

Jump to

Keyboard shortcuts

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