Documentation ¶
Overview ¶
Package fileutil contains routines and clients for moving bytes around between object stores and files, or files and files.
Index ¶
- func CopyFile(dest, source string) error
- func FileType(path string) (string, error)
- func FileTypes(paths []string) ([]string, error)
- func HashFile(fname string) (string, error)
- func IsVideo(path string) bool
- func MimeTypeOrGeneric(path string) string
- func TranslateSubPath(src, target, path string) (string, error)
- type FileUtil
- type FileUtilOption
- type Stager
- type Translator
- type TranslatorOption
- type Unstager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyFile ¶
CopyFile copies bytes from the source filename to the dest filename. If they are determined to be the same file, it does nothing and returns a nil error. If the destination directory does not exist, it is created via os.MkdirAll with permissions 0775.
func FileType ¶
FileType returns the mime type string for a given file path, e.g., "image/jpeg" for a JPEG image. Returns "inode/directory" if the referenced path is a directory name.
func MimeTypeOrGeneric ¶
MimeTypeOrGeneric produces a mime type from the path extension, else octet-stream.
func TranslateSubPath ¶
TranslateSubPath finds the components of path that are under the source path, and appends them to the target path.
Types ¶
type FileUtil ¶
type FileUtil struct {
// contains filtered or unexported fields
}
FileUtil provides operations for accessing files and object stores and performing common operations between them.
func New ¶
func New(opts ...FileUtilOption) (*FileUtil, error)
New produces a new FileUtil that can access an object store with the given credentials. This allows them to be omitted in object store URLs.
func (*FileUtil) PullToFile ¶
PullToFile reads the bytes given by the uri (can be a file name) and writes them to the file named by dest. The destination must be a complete file name, not a directory.
func (*FileUtil) PushFromFile ¶
PushFromFile reads the byte at the source file and attempts to write them to the given URI. If the URI represents a file, it is treated as a file name. If it is a file name and ends in /, it is treated as a directory and the name will come from the source file name.
type FileUtilOption ¶
type FileUtilOption func(*fileUtilMod)
FileUtilOption is an option that modifies behavior of the FileUtil when passed to New.
func WithS3Credentials ¶
func WithS3Credentials(user, pass string) FileUtilOption
WithS3Credentials creates a FileUtilOption that sets the S3 user and password for S3 API operations.
type Stager ¶
Stager is a function that gets a file from a source URI and pushes it to a destination (local) file path.
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator translates path names that are under a common source directory. The source is removed and replaced with the target.
func NewTranslator ¶
func NewTranslator(source, target string, opts ...TranslatorOption) *Translator
NewTranslator creates a path translator from the given source and target paths. The file name to be translated must be under the source tree for translation to work properly. This works best when both source and target paths are absolute or relative to the same parent.
func (*Translator) Translate ¶
func (t *Translator) Translate(path string) (string, error)
Translate finds the source prefix and removes it, replacing it with the target value.
func (*Translator) Untranslate ¶
func (t *Translator) Untranslate(path string) (string, error)
Untranslate removes the target prefix and replaces it with the source. It undoes the translate operation.
type TranslatorOption ¶
type TranslatorOption func(*Translator)
TranslatorOption provides options to the file path translator.
func WithStager ¶
func WithStager(s Stager) TranslatorOption
WithStage instructs the translator to not only translate paths, but to stage files during the translate processes. For example, it may be that an input translator should pull files from an HTTP service and store them on disk. Turning this on allows that to happen. Otherwise it merely does path translation.
This does not change the behavior of Untranslate.
func WithUnstager ¶
func WithUnstager(u Unstager) TranslatorOption
WithUnstage instructs the translator to copy files while untranslating, e.g., to push a file to an originating service. See WithStage for details.
This does not change the behavior of Translate.