Documentation
¶
Overview ¶
Helpers for working with files and filesystems
Index ¶
- Constants
- Variables
- func AddMimeTypeFile(filename string)
- func ChecksumFile(filename string, fn interface{}) ([]byte, error)
- func CopyDir(root string, fn CopyEntryFunc) error
- func CopyFile(source interface{}, destination interface{}) error
- func GetMimeType(filenameOrReader interface{}, fallback ...string) string
- func InitMime()
- func IsModifiedAfter(stat os.FileInfo, current string) bool
- func IsTerminal() bool
- func MustExpandUser(path string) string
- func MustReadAll(filename string) []byte
- func MustReadAllString(filename string) string
- func MustWriteFile(reader io.Reader, filename string) int64
- func Open(uri string) (io.Reader, error)
- func OpenWithOptions(uri string, options OpenOptions) (io.Reader, error)
- func ReadAll(filename string) ([]byte, error)
- func ReadAllLines(filename string) ([]string, error)
- func ReadAllString(filename string) (string, error)
- func ReadFirstLine(filename string) (string, error)
- func RegisterOpenHandler(scheme string, handler OpenHandler)
- func RemoveOpenHandler(scheme string)
- func WriteFile(reader io.Reader, filename string) (int64, error)
- type CopyEntryFunc
- type DirReader
- type DirReaderOption
- type DirReaderOptions
- type OpenHandler
- type OpenOptions
- type PostReadCloser
- type RewriteFileSystem
- type SkipFunc
Constants ¶
const DefaultOpenTimeout = time.Duration(10 * time.Second)
Variables ¶
var DirExists = pathutil.DirExists
Alias functions from pathutil as a convenience
var Exists = pathutil.Exists
var ExpandUser = pathutil.ExpandUser
var FileExists = pathutil.FileExists
var IsAppend = pathutil.IsAppend
var IsAppendable = pathutil.IsAppendable
var IsCharDevice = pathutil.IsCharDevice
var IsDevice = pathutil.IsDevice
var IsExclusive = pathutil.IsExclusive
var IsNamedPipe = pathutil.IsNamedPipe
var IsNonemptyDir = pathutil.IsNonemptyDir
var IsNonemptyExecutableFile = pathutil.IsNonemptyExecutableFile
var IsNonemptyFile = pathutil.IsNonemptyFile
var IsReadable = pathutil.IsReadable
var IsSetgid = pathutil.IsSetgid
var IsSetuid = pathutil.IsSetuid
var IsSocket = pathutil.IsSocket
var IsSticky = pathutil.IsSticky
var IsSymlink = pathutil.IsSymlink
var IsTemporary = pathutil.IsTemporary
var IsWritable = pathutil.IsWritable
var LinkExists = pathutil.LinkExists
Functions ¶
func AddMimeTypeFile ¶ added in v1.6.14
func AddMimeTypeFile(filename string)
func ChecksumFile ¶ added in v1.7.7
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
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 IsModifiedAfter ¶ added in v1.6.27
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 MustReadAll ¶
func MustReadAllString ¶
func MustWriteFile ¶ added in v1.6.26
Same as WriteFile, but will panic if the file cannot be written.
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 ReadAllLines ¶ added in v1.6.13
func ReadAllString ¶
func ReadFirstLine ¶ added in v1.6.13
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
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 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) SetSkipFunc ¶ added in v1.6.32
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
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