fileutil

package
v1.7.19 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 23 Imported by: 28

Documentation

Overview

Helpers for working with files and filesystems

Index

Constants

View Source
const DefaultOpenTimeout = time.Duration(10 * time.Second)

Variables

View Source
var DirExists = pathutil.DirExists

Alias functions from pathutil as a convenience

View Source
var Exists = pathutil.Exists
View Source
var ExpandUser = pathutil.ExpandUser
View Source
var FileExists = pathutil.FileExists
View Source
var IsAppend = pathutil.IsAppend
View Source
var IsAppendable = pathutil.IsAppendable
View Source
var IsCharDevice = pathutil.IsCharDevice
View Source
var IsDevice = pathutil.IsDevice
View Source
var IsExclusive = pathutil.IsExclusive
View Source
var IsNamedPipe = pathutil.IsNamedPipe
View Source
var IsNonemptyDir = pathutil.IsNonemptyDir
View Source
var IsNonemptyExecutableFile = pathutil.IsNonemptyExecutableFile
View Source
var IsNonemptyFile = pathutil.IsNonemptyFile
View Source
var IsReadable = pathutil.IsReadable
View Source
var IsSetgid = pathutil.IsSetgid
View Source
var IsSetuid = pathutil.IsSetuid
View Source
var IsSocket = pathutil.IsSocket
View Source
var IsSticky = pathutil.IsSticky
View Source
var IsSymlink = pathutil.IsSymlink
View Source
var IsTemporary = pathutil.IsTemporary
View Source
var IsWritable = pathutil.IsWritable
View Source
var LinkExists = pathutil.LinkExists

Functions

func AddMimeTypeFile added in v1.6.14

func AddMimeTypeFile(filename string)

func ChecksumFile added in v1.7.7

func ChecksumFile(filename string, fn interface{}) ([]byte, error)

func CopyDir added in v1.6.33

func CopyDir(root string, fn CopyEntryFunc) error

Recursively walk the entries of a given directory, calling CopyEntryFunc for each entry. The io.Writer returned from the function will have that file's contents written to it. If the io.Writer is nil, the file will not be written anywhere but no error will be returned. If CopyEntryFunc returns an error, the behavior will be consistent with filepath.WalkFunc

func CopyFile added in v1.7.17

func CopyFile(source interface{}, destination interface{}) error

Copy a file from one place to another. Source can be an io.Reader or string. If source is a string, the string will be passed to the Open() function as a URL. Destination can be an io.Writer or string. If destination is a string, it will be treated as a local filesystem path to write the data read from source to.

If either source or destination implements io.Closer, thee files will be closed before this function returns.

func GetMimeType added in v1.6.14

func GetMimeType(filenameOrReader interface{}, fallback ...string) string

GetMimeType goes out of its way to really, really try to figure out the MIME type of a given filename or io.Reader. If the first argument satisfies the io.Seeker interface, the seeker will Seek() back to the beginning. If it satisfies the io.Closer interface, it will be closed.

func InitMime added in v1.6.14

func InitMime()

func IsModifiedAfter added in v1.6.27

func IsModifiedAfter(stat os.FileInfo, current string) bool

Return true if the given FileInfo sports a ModTime later than the current file.

func IsTerminal

func IsTerminal() bool

func MustExpandUser added in v1.6.27

func MustExpandUser(path string) string

func MustReadAll

func MustReadAll(filename string) []byte

func MustReadAllString

func MustReadAllString(filename string) string

func MustWriteFile added in v1.6.26

func MustWriteFile(reader io.Reader, filename string) int64

Same as WriteFile, but will panic if the file cannot be written.

func Open added in v1.7.17

func Open(uri string) (io.Reader, error)

Calls OpenWithOptions with no options set.

func OpenWithOptions added in v1.7.17

func OpenWithOptions(uri string, options OpenOptions) (io.Reader, error)

A generic URL opener that supports various schemes and returns an io.Reader. Supported URL schemes include: file://, http://, https://, ftp://, sftp://. If no scheme is provided, the URL is interpreted as a local filesystem path.

func ReadAll

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

func ReadAllLines added in v1.6.13

func ReadAllLines(filename string) ([]string, error)

func ReadAllString

func ReadAllString(filename string) (string, error)

func ReadFirstLine added in v1.6.13

func ReadFirstLine(filename string) (string, error)

func RegisterOpenHandler added in v1.7.17

func RegisterOpenHandler(scheme string, handler OpenHandler)

Register a handler for a new or existing URL scheme, for use with Open() and OpenWithOptions()

func RemoveOpenHandler added in v1.7.17

func RemoveOpenHandler(scheme string)

Removes a registered URL scheme handler.

func WriteFile added in v1.6.26

func WriteFile(reader io.Reader, filename string) (int64, error)

Write the contents of the given reader to the specified filename. Filename paths containing tilde (~) will automatically expand to the current user's home directory, and all intermediate parent directories will be automatically created. Will return the number of bytes written, or an error.

Types

type CopyEntryFunc added in v1.6.33

type CopyEntryFunc func(path string, info os.FileInfo, err error) (io.Writer, error)

type DirReader added in v1.6.32

type DirReader struct {
	// contains filtered or unexported fields
}

A DirReader provides a streaming io.Reader interface to all files in a given directory, with options for handling unreadable entries and recursion.

func NewDirReader added in v1.6.32

func NewDirReader(path string, options ...DirReaderOption) *DirReader

func (*DirReader) Close added in v1.6.32

func (self *DirReader) Close() error

close open files and reset the internal reader

func (*DirReader) Read added in v1.6.32

func (self *DirReader) Read(b []byte) (int, error)

func (*DirReader) SetSkipFunc added in v1.6.32

func (self *DirReader) SetSkipFunc(fn SkipFunc)

Set a function that will be called for each path encountered while reading. If this function returns true, that path (and its descedants) will not be read.

type DirReaderOption added in v1.6.32

type DirReaderOption int
const (
	NoRecursive DirReaderOption = iota
	FailOnError
)

type DirReaderOptions added in v1.6.32

type DirReaderOptions []DirReaderOption

func (DirReaderOptions) Has added in v1.6.32

func (self DirReaderOptions) Has(option DirReaderOption) bool

type OpenHandler added in v1.7.17

type OpenHandler func(*url.URL, OpenOptions) (io.ReadCloser, error)

type OpenOptions added in v1.7.17

type OpenOptions struct {
	Timeout  time.Duration
	Insecure bool
}

func (OpenOptions) GetTimeout added in v1.7.17

func (self OpenOptions) GetTimeout() time.Duration

type PostReadCloser added in v1.7.17

type PostReadCloser struct {
	// contains filtered or unexported fields
}

func NewPostReadCloser added in v1.7.17

func NewPostReadCloser(upstream io.ReadCloser, closer func(io.ReadCloser) error) *PostReadCloser

Implements an io.ReadCloser that can be configured to perform cleanup options whenever the Close() function is called.

func (*PostReadCloser) Close added in v1.7.17

func (self *PostReadCloser) Close() error

func (*PostReadCloser) Read added in v1.7.17

func (self *PostReadCloser) Read(b []byte) (int, error)

type RewriteFileSystem

type RewriteFileSystem struct {
	FileSystem http.FileSystem
	Find       *regexp.Regexp
	Replace    string
	MustMatch  bool
}

func (RewriteFileSystem) Open

func (self RewriteFileSystem) Open(name string) (http.File, error)

type SkipFunc added in v1.6.32

type SkipFunc func(string) bool

Jump to

Keyboard shortcuts

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