Documentation ¶
Index ¶
- Constants
- Variables
- func CopyFile(ctx context.Context, src FileReader, dest File, perm ...Permissions) error
- func CopyFileBuf(ctx context.Context, src FileReader, dest File, buf *[]byte, ...) error
- func CopyRecursive(ctx context.Context, src, dest File, patterns ...string) error
- func FileContentHash(ctx context.Context, fileReader FileReader, hashFunc ContentHashFunc) (string, error)
- func FileInfoToFileCallback(fileCallback func(File) error) func(*FileInfo) error
- func FileReaderContentHashIndex(ctx context.Context, fileReades []FileReader, hash string) (int, error)
- func FileReaderLocalPathIndex(fileReades []FileReader, localPath string) int
- func FileReaderNameIndex(fileReades []FileReader, filename string) int
- func FileReaderNotExistsIndex(fileReades []FileReader, filename string) int
- func FilesToNames(files []File) []string
- func FilesToPaths(files []File) []string
- func FilesToURLs(files []File) []string
- func IdenticalDirContents(ctx context.Context, dirA, dirB File, recursive bool) (identical bool, err error)
- func IdenticalFileContents(ctx context.Context, files ...FileReader) (identical bool, err error)
- func IsRegistered(fs FileSystem) bool
- func Move(ctx context.Context, source, destination File) error
- func ReadAllContext(ctx context.Context, r io.Reader) ([]byte, error)
- func Register(fs FileSystem) int
- func Remove(fileURIs ...string) error
- func RemoveErrDoesNotExist(err error) error
- func RemoveFile(file File) error
- func RemoveFiles(files ...File) error
- func SameFile(a, b File) bool
- func ServeFileHTTP(response http.ResponseWriter, request *http.Request, file FileReader, ...)
- func ServeFileHTTPHandler(file FileReader, contentType ...string) http.Handler
- func SortByModified(files []File)
- func SortByModifiedDirsFirst(files []File)
- func SortByName(files []File)
- func SortByNameDirsFirst(files []File)
- func SortByPath(files []File)
- func SortBySize(files []File)
- func Unregister(fs FileSystem) int
- func WriteAllContext(ctx context.Context, w io.Writer, data []byte) error
- type AppendFileSystem
- type AppendWriterFileSystem
- type ContentHashFunc
- type CopyFileSystem
- type ErrAlreadyExists
- type ErrDoesNotExist
- type ErrIsDirectory
- type ErrIsNotDirectory
- type ErrPermission
- type ErrUnsupported
- type Event
- type ExistsFileSystem
- type File
- func CleanFilePath(uri string) File
- func CurrentWorkingDir() File
- func Executable() File
- func Filef(format string, args ...any) File
- func HomeDir() File
- func JoinCleanFilePath(uriParts ...string) File
- func MakeTempDir() (File, error)
- func MustMakeTempDir() File
- func StringsToFiles(fileURIs []string) []File
- func TempDir() File
- func TempFile(ext ...string) File
- func (file File) AbsPath() string
- func (file File) Append(ctx context.Context, data []byte, perm ...Permissions) error
- func (file File) AppendString(ctx context.Context, str string, perm ...Permissions) error
- func (file File) CheckExists() error
- func (file File) CheckIsDir() error
- func (file File) ContentHash() (string, error)
- func (file File) ContentHashContext(ctx context.Context) (string, error)
- func (file File) Dir() File
- func (file File) DirAndName() (dir File, name string)
- func (file File) Exists() bool
- func (file File) Ext() string
- func (file File) ExtLower() string
- func (file File) FileSystem() FileSystem
- func (file File) GobDecode(gobBytes []byte) error
- func (file File) GobEncode() ([]byte, error)
- func (file File) Group() (string, error)
- func (file File) HasAbsPath() bool
- func (file File) Info() *FileInfo
- func (file File) IsDir() bool
- func (file File) IsEmptyDir() bool
- func (file File) IsHidden() bool
- func (file File) IsReadable() bool
- func (file File) IsRegular() bool
- func (file File) IsSymbolicLink() bool
- func (file File) IsWriteable() bool
- func (file File) Join(pathParts ...string) File
- func (file File) Joinf(format string, args ...any) File
- func (file File) ListDir(callback func(File) error, patterns ...string) error
- func (file File) ListDirChan(cancel <-chan error, patterns ...string) (<-chan File, <-chan error)
- func (file File) ListDirContext(ctx context.Context, callback func(File) error, patterns ...string) error
- func (file File) ListDirInfo(callback func(*FileInfo) error, patterns ...string) error
- func (file File) ListDirInfoContext(ctx context.Context, callback func(*FileInfo) error, patterns ...string) error
- func (file File) ListDirInfoRecursive(callback func(*FileInfo) error, patterns ...string) error
- func (file File) ListDirInfoRecursiveContext(ctx context.Context, callback func(*FileInfo) error, patterns ...string) error
- func (file File) ListDirMax(max int, patterns ...string) (files []File, err error)
- func (file File) ListDirMaxContext(ctx context.Context, max int, patterns ...string) (files []File, err error)
- func (file File) ListDirRecursive(callback func(File) error, patterns ...string) error
- func (file File) ListDirRecursiveChan(cancel <-chan error, patterns ...string) (<-chan File, <-chan error)
- func (file File) ListDirRecursiveContext(ctx context.Context, callback func(File) error, patterns ...string) error
- func (file File) ListDirRecursiveMax(max int, patterns ...string) (files []File, err error)
- func (file File) ListDirRecursiveMaxContext(ctx context.Context, max int, patterns ...string) (files []File, err error)
- func (file File) LocalPath() string
- func (file File) MakeAllDirs(perm ...Permissions) error
- func (file File) MakeDir(perm ...Permissions) error
- func (file File) Modified() time.Time
- func (file File) MoveTo(destination File) error
- func (file File) MustLocalPath() string
- func (file File) Name() string
- func (file File) OpenAppendWriter(perm ...Permissions) (WriteCloser, error)
- func (file File) OpenReadSeeker() (ReadSeekCloser, error)
- func (file File) OpenReadWriter(perm ...Permissions) (ReadWriteSeekCloser, error)
- func (file File) OpenReader() (ReadCloser, error)
- func (file File) OpenWriter(perm ...Permissions) (WriteCloser, error)
- func (file File) ParseRawURI() (fs FileSystem, fsPath string)
- func (file File) Path() string
- func (file File) PathWithSlashes() string
- func (file File) Permissions() Permissions
- func (file File) RawURI() string
- func (file File) ReadAll() (data []byte, err error)
- func (file File) ReadAllContentHash(ctx context.Context) (data []byte, hash string, err error)
- func (file File) ReadAllContext(ctx context.Context) (data []byte, err error)
- func (file File) ReadAllString() (string, error)
- func (file File) ReadAllStringContext(ctx context.Context) (string, error)
- func (file File) ReadFrom(reader io.Reader) (n int64, err error)
- func (file File) ReadJSON(ctx context.Context, output any) error
- func (file File) ReadXML(ctx context.Context, output any) error
- func (file File) Remove() error
- func (file File) RemoveDirContents(patterns ...string) error
- func (file File) RemoveDirContentsContext(ctx context.Context, patterns ...string) error
- func (file File) RemoveDirContentsRecursive() error
- func (file File) RemoveDirContentsRecursiveContext(ctx context.Context) error
- func (file File) RemoveRecursive() error
- func (file File) RemoveRecursiveContext(ctx context.Context) error
- func (file File) Rename(newName string) (renamedFile File, err error)
- func (file File) Renamef(newNameFormat string, args ...any) (renamedFile File, err error)
- func (file File) SetGroup(group string) error
- func (file File) SetPermissions(perm Permissions) error
- func (file File) SetUser(user string) error
- func (file File) Size() int64
- func (file File) Stat() (iofs.FileInfo, error)
- func (file File) StdDirEntry() StdDirEntry
- func (file File) StdFS() StdFS
- func (file File) String() string
- func (file File) ToAbsPath() File
- func (file File) Touch(perm ...Permissions) error
- func (file File) TrimExt() File
- func (file File) Truncate(newSize int64) error
- func (file File) URL() string
- func (file File) User() (string, error)
- func (file File) VolumeName() string
- func (file File) Watch(onEvent func(File, Event)) (cancel func() error, err error)
- func (file File) WriteAll(data []byte, perm ...Permissions) error
- func (file File) WriteAllContext(ctx context.Context, data []byte, perm ...Permissions) error
- func (file File) WriteAllString(str string, perm ...Permissions) error
- func (file File) WriteAllStringContext(ctx context.Context, str string, perm ...Permissions) error
- func (file File) WriteJSON(ctx context.Context, input any, indent ...string) (err error)
- func (file File) WriteTo(writer io.Writer) (n int64, err error)
- func (file File) WriteXML(ctx context.Context, input any, indent ...string) (err error)
- type FileInfo
- type FileInfoCache
- type FileReader
- type FileSystem
- type GroupFileSystem
- type InvalidFileSystem
- func (fs InvalidFileSystem) AbsPath(filePath string) string
- func (InvalidFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error
- func (fs InvalidFileSystem) CleanPathFromURI(uri string) string
- func (InvalidFileSystem) Close() error
- func (InvalidFileSystem) CopyFile(ctx context.Context, srcFile string, destFile string, buf *[]byte) error
- func (InvalidFileSystem) Exists(filePath string) bool
- func (InvalidFileSystem) Group(filePath string) (string, error)
- func (fs InvalidFileSystem) ID() (string, error)
- func (InvalidFileSystem) IsAbsPath(filePath string) bool
- func (InvalidFileSystem) IsHidden(filePath string) bool
- func (InvalidFileSystem) IsSymbolicLink(filePath string) bool
- func (fs InvalidFileSystem) JoinCleanFile(uri ...string) File
- func (fs InvalidFileSystem) JoinCleanPath(uriParts ...string) string
- func (InvalidFileSystem) ListDirInfo(ctx context.Context, dirPath string, callback func(*FileInfo) error, ...) error
- func (InvalidFileSystem) ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(*FileInfo) error, ...) error
- func (InvalidFileSystem) ListDirMax(ctx context.Context, dirPath string, n int, patterns []string) (files []File, err error)
- func (InvalidFileSystem) MakeAllDirs(dirPath string, perm []Permissions) error
- func (InvalidFileSystem) MakeDir(dirPath string, perm []Permissions) error
- func (InvalidFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error)
- func (InvalidFileSystem) Move(filePath string, destPath string) error
- func (fs InvalidFileSystem) Name() string
- func (InvalidFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (InvalidFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
- func (InvalidFileSystem) OpenReader(filePath string) (ReadCloser, error)
- func (InvalidFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (fs InvalidFileSystem) Prefix() string
- func (InvalidFileSystem) ReadAll(ctx context.Context, filePath string) ([]byte, error)
- func (InvalidFileSystem) ReadableWritable() (readable, writable bool)
- func (InvalidFileSystem) Remove(filePath string) error
- func (InvalidFileSystem) Rename(filePath string, newName string) (string, error)
- func (InvalidFileSystem) RootDir() File
- func (InvalidFileSystem) Separator() string
- func (InvalidFileSystem) SetGroup(filePath string, group string) error
- func (InvalidFileSystem) SetPermissions(filePath string, perm Permissions) error
- func (InvalidFileSystem) SetUser(filePath string, user string) error
- func (fs InvalidFileSystem) SplitDirAndName(filePath string) (dir, name string)
- func (fs InvalidFileSystem) SplitPath(filePath string) []string
- func (InvalidFileSystem) Stat(filePath string) (iofs.FileInfo, error)
- func (fs InvalidFileSystem) String() string
- func (InvalidFileSystem) Touch(filePath string, perm []Permissions) error
- func (InvalidFileSystem) Truncate(filePath string, size int64) error
- func (fs InvalidFileSystem) URL(cleanPath string) string
- func (InvalidFileSystem) User(filePath string) (string, error)
- func (InvalidFileSystem) VolumeName(filePath string) string
- func (InvalidFileSystem) Watch(filePath string, onEvent func(File, Event)) (cancel func() error, err error)
- func (InvalidFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error
- type ListDirMaxFileSystem
- type ListDirRecursiveFileSystem
- type LocalFileSystem
- func (local *LocalFileSystem) AbsPath(filePath string) string
- func (local *LocalFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error
- func (local *LocalFileSystem) CleanPathFromURI(uri string) string
- func (*LocalFileSystem) Close() error
- func (local *LocalFileSystem) CopyFile(ctx context.Context, srcFilePath string, destFilePath string, buf *[]byte) error
- func (local *LocalFileSystem) CreateSymbolicLink(oldFile, newFile File) error
- func (local *LocalFileSystem) Group(filePath string) (string, error)
- func (local *LocalFileSystem) ID() (string, error)
- func (local *LocalFileSystem) IsAbsPath(filePath string) bool
- func (local *LocalFileSystem) IsHidden(filePath string) bool
- func (local *LocalFileSystem) IsSymbolicLink(filePath string) bool
- func (local *LocalFileSystem) JoinCleanFile(uri ...string) File
- func (local *LocalFileSystem) JoinCleanPath(uriParts ...string) string
- func (local *LocalFileSystem) ListDirInfo(ctx context.Context, dirPath string, callback func(*FileInfo) error, ...) (err error)
- func (local *LocalFileSystem) ListDirMax(ctx context.Context, dirPath string, max int, patterns []string) (files []File, err error)
- func (local *LocalFileSystem) MakeAllDirs(dirPath string, perm []Permissions) error
- func (local *LocalFileSystem) MakeDir(dirPath string, perm []Permissions) error
- func (local *LocalFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error)
- func (local *LocalFileSystem) Move(filePath string, destPath string) error
- func (local *LocalFileSystem) Name() string
- func (local *LocalFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (local *LocalFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
- func (local *LocalFileSystem) OpenReader(filePath string) (ReadCloser, error)
- func (local *LocalFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (local *LocalFileSystem) Prefix() string
- func (local *LocalFileSystem) ReadAll(ctx context.Context, filePath string) ([]byte, error)
- func (local *LocalFileSystem) ReadSymbolicLink(file File) (linked File, err error)
- func (local *LocalFileSystem) ReadableWritable() (readable, writable bool)
- func (local *LocalFileSystem) Remove(filePath string) error
- func (local *LocalFileSystem) Rename(filePath string, newName string) (newPath string, err error)
- func (local *LocalFileSystem) RootDir() File
- func (local *LocalFileSystem) Separator() string
- func (local *LocalFileSystem) SetGroup(filePath string, group string) error
- func (local *LocalFileSystem) SetPermissions(filePath string, perm Permissions) error
- func (local *LocalFileSystem) SetUser(filePath string, username string) error
- func (*LocalFileSystem) SplitDirAndName(filePath string) (dir, name string)
- func (local *LocalFileSystem) SplitPath(filePath string) []string
- func (local *LocalFileSystem) Stat(filePath string) (iofs.FileInfo, error)
- func (local *LocalFileSystem) String() string
- func (local *LocalFileSystem) Touch(filePath string, perm []Permissions) error
- func (local *LocalFileSystem) Truncate(filePath string, newSize int64) error
- func (local *LocalFileSystem) URL(cleanPath string) string
- func (local *LocalFileSystem) User(filePath string) (string, error)
- func (local *LocalFileSystem) VolumeName(filePath string) string
- func (local *LocalFileSystem) Watch(filePath string, onEvent func(File, Event)) (cancel func() error, err error)
- func (local *LocalFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error
- type Logger
- type LoggerFunc
- type MakeAllDirsFileSystem
- type MemFile
- func NewMemFile(name string, data []byte) MemFile
- func ReadAllMemFile(ctx context.Context, r io.Reader, name string) (MemFile, error)
- func ReadMemFile(ctx context.Context, fileReader FileReader) (MemFile, error)
- func ReadMemFileRename(ctx context.Context, fileReader FileReader, name string) (MemFile, error)
- func UnzipToMemFiles(ctx context.Context, zipFile FileReader) ([]MemFile, error)
- func (f MemFile) CheckExists() error
- func (f MemFile) ContentHash() (string, error)
- func (f MemFile) ContentHashContext(ctx context.Context) (string, error)
- func (f MemFile) Exists() bool
- func (f MemFile) Ext() string
- func (f *MemFile) GobDecode(gobBytes []byte) error
- func (f MemFile) GobEncode() ([]byte, error)
- func (MemFile) LocalPath() string
- func (f MemFile) Name() string
- func (f MemFile) OpenReadSeeker() (ReadSeekCloser, error)
- func (f MemFile) OpenReader() (ReadCloser, error)
- func (f MemFile) ReadAll() (data []byte, err error)
- func (f MemFile) ReadAllContentHash(ctx context.Context) (data []byte, hash string, err error)
- func (f MemFile) ReadAllContext(ctx context.Context) (data []byte, err error)
- func (f MemFile) ReadAllString() (string, error)
- func (f MemFile) ReadAllStringContext(ctx context.Context) (string, error)
- func (f MemFile) ReadAt(p []byte, off int64) (n int, err error)
- func (f MemFile) ReadJSON(ctx context.Context, output any) error
- func (f MemFile) ReadXML(ctx context.Context, output any) error
- func (f MemFile) Size() int64
- func (f MemFile) Stat() (iofs.FileInfo, error)
- func (f MemFile) String() string
- func (f *MemFile) Write(b []byte) (int, error)
- func (f MemFile) WriteTo(writer io.Writer) (n int64, err error)
- type MemFileSystem
- func (fs *MemFileSystem) AbsPath(filePath string) string
- func (fs *MemFileSystem) AddMemFile(f MemFile, modified time.Time) (File, error)
- func (fs *MemFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error
- func (fs *MemFileSystem) CleanPathFromURI(uri string) string
- func (fs *MemFileSystem) Clear()
- func (fs *MemFileSystem) Close() error
- func (fs *MemFileSystem) CopyFile(ctx context.Context, srcFile string, destFile string, buf *[]byte) error
- func (fs *MemFileSystem) Exists(filePath string) bool
- func (fs *MemFileSystem) ID() (string, error)
- func (fs *MemFileSystem) IsAbsPath(filePath string) bool
- func (*MemFileSystem) IsHidden(filePath string) bool
- func (*MemFileSystem) IsSymbolicLink(filePath string) bool
- func (fs *MemFileSystem) JoinCleanFile(uri ...string) File
- func (fs *MemFileSystem) JoinCleanPath(uriParts ...string) string
- func (*MemFileSystem) ListDirInfo(ctx context.Context, dirPath string, callback func(*FileInfo) error, ...) error
- func (fs *MemFileSystem) MakeAllDirs(dirPath string, perm []Permissions) error
- func (fs *MemFileSystem) MakeDir(dirPath string, perm []Permissions) error
- func (*MemFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error)
- func (fs *MemFileSystem) Move(filePath string, destPath string) error
- func (*MemFileSystem) Name() string
- func (fs *MemFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (fs *MemFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
- func (fs *MemFileSystem) OpenReader(filePath string) (iofs.File, error)
- func (fs *MemFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (fs *MemFileSystem) Prefix() string
- func (fs *MemFileSystem) ReadAll(ctx context.Context, filePath string) ([]byte, error)
- func (fs *MemFileSystem) ReadableWritable() (readable, writable bool)
- func (fs *MemFileSystem) Remove(filePath string) error
- func (fs *MemFileSystem) Rename(filePath string, newName string) (string, error)
- func (fs *MemFileSystem) RootDir() File
- func (fs *MemFileSystem) Separator() string
- func (fs *MemFileSystem) SetReadOnly(readOnly bool)
- func (fs *MemFileSystem) SplitDirAndName(filePath string) (dir, name string)
- func (fs *MemFileSystem) SplitPath(filePath string) []string
- func (fs *MemFileSystem) Stat(filePath string) (iofs.FileInfo, error)
- func (fs *MemFileSystem) String() string
- func (fs *MemFileSystem) Touch(filePath string, perm []Permissions) error
- func (fs *MemFileSystem) Truncate(filePath string, newSize int64) error
- func (fs *MemFileSystem) URL(cleanPath string) string
- func (fs *MemFileSystem) Volume() string
- func (fs *MemFileSystem) VolumeName(filePath string) string
- func (fs *MemFileSystem) Watch(filePath string, onEvent func(File, Event)) (cancel func() error, err error)
- func (fs *MemFileSystem) WithID(id string) *MemFileSystem
- func (fs *MemFileSystem) WithVolume(volume string) *MemFileSystem
- func (fs *MemFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error
- type MoveFileSystem
- type Permissions
- func (perm Permissions) Can(p Permissions) bool
- func (perm Permissions) CanAllExecute() bool
- func (perm Permissions) CanAllRead() bool
- func (perm Permissions) CanAllReadWrite() bool
- func (perm Permissions) CanAllWrite() bool
- func (perm Permissions) CanGroupExecute() bool
- func (perm Permissions) CanGroupRead() bool
- func (perm Permissions) CanGroupReadWrite() bool
- func (perm Permissions) CanGroupWrite() bool
- func (perm Permissions) CanOthersExecute() bool
- func (perm Permissions) CanOthersRead() bool
- func (perm Permissions) CanOthersReadWrite() bool
- func (perm Permissions) CanOthersWrite() bool
- func (perm Permissions) CanUserAndGroupRead() bool
- func (perm Permissions) CanUserAndGroupReadWrite() bool
- func (perm Permissions) CanUserExecute() bool
- func (perm Permissions) CanUserRead() bool
- func (perm Permissions) CanUserReadWrite() bool
- func (perm Permissions) CanUserWrite() bool
- func (perm Permissions) Executable() (user, group, others bool)
- func (perm Permissions) FileMode(isDir bool) os.FileMode
- func (perm Permissions) Readable() (user, group, others bool)
- func (perm Permissions) Writable() (user, group, others bool)
- type PermissionsFileSystem
- type ReadAllFileSystem
- type ReadCloser
- type ReadOnlyBase
- func (*ReadOnlyBase) MakeDir(dirPath string, perm []Permissions) error
- func (*ReadOnlyBase) MatchAnyPattern(name string, patterns []string) (bool, error)
- func (*ReadOnlyBase) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
- func (*ReadOnlyBase) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
- func (*ReadOnlyBase) ReadableWritable() (readable, writable bool)
- func (*ReadOnlyBase) Remove(filePath string) error
- func (*ReadOnlyBase) SetGroup(filePath string, group string) error
- func (*ReadOnlyBase) SetPermissions(filePath string, perm Permissions) error
- func (*ReadOnlyBase) SetUser(filePath string, user string) error
- type ReadSeekCloser
- type ReadWriteSeekCloser
- type RenameFileSystem
- type SentinelError
- type StdDirEntry
- type StdFS
- func (f StdFS) Glob(pattern string) (names []string, err error)
- func (f StdFS) Open(name string) (iofs.File, error)
- func (f StdFS) ReadDir(name string) ([]iofs.DirEntry, error)
- func (f StdFS) ReadFile(name string) ([]byte, error)
- func (f StdFS) Stat(name string) (iofs.FileInfo, error)
- func (f StdFS) Sub(dir string) (iofs.FS, error)
- type TouchFileSystem
- type TruncateFileSystem
- type UserFileSystem
- type VolumeNameFileSystem
- type WatchFileSystem
- type WriteAllFileSystem
- type WriteCloser
- type WriteSeekCloser
Constants ¶
const ( // LocalPrefix is the prefix of the LocalFileSystem LocalPrefix = "file://" // Separator used in LocalFileSystem paths Separator = string(filepath.Separator) )
const InvalidFile = File("")
InvalidFile is a file with an empty path and thus invalid.
const PrefixSeparator = "://"
Variables ¶
var ErrEmptyPath = NewErrDoesNotExist("")
ErrEmptyPath indications an empty file path
Functions ¶
func CopyFile ¶
func CopyFile(ctx context.Context, src FileReader, dest File, perm ...Permissions) error
CopyFile copies a single file between different file systems. If dest has a path that does not exist, then all directories up to that path will be created. If dest is an existing directory, then a file with the base name of src will be created there.
func CopyFileBuf ¶
func CopyFileBuf(ctx context.Context, src FileReader, dest File, buf *[]byte, perm ...Permissions) error
CopyFileBuf copies a single file between different file systems. If dest has a path that does not exist, then all directories up to that path will be created. If dest is an existing directory, then a file with the base name of src will be created there. An pointer to a []byte variable must be passed for buf. If that variable holds a non zero length byte slice then this slice will be used as buffer, else a byte slice will be allocated and assigned to the variable. Use this function to re-use buffers between CopyFileBuf calls.
func CopyRecursive ¶
CopyRecursive can copy between files of different file systems. The filter patterns are applied on filename level, not the whole path.
func FileContentHash ¶
func FileContentHash(ctx context.Context, fileReader FileReader, hashFunc ContentHashFunc) (string, error)
FileContentHash returns the hashFunc result for fileReader
func FileInfoToFileCallback ¶
FileInfoToFileCallback converts a File callback function into a FileInfo callback function that is calling the passed fileCallback with the FileInfo.File.
func FileReaderContentHashIndex ¶
func FileReaderContentHashIndex(ctx context.Context, fileReades []FileReader, hash string) (int, error)
FileReaderContentHashIndex returns the slice index of the first FileReader with the passed hash returned from its ContentHashContext method or -1 in case of no match.
func FileReaderLocalPathIndex ¶
func FileReaderLocalPathIndex(fileReades []FileReader, localPath string) int
FileReaderLocalPathIndex returns the slice index of the first FileReader with the passed localPath returned from its LocalPath method or -1 in case of no match.
func FileReaderNameIndex ¶
func FileReaderNameIndex(fileReades []FileReader, filename string) int
FileReaderNameIndex returns the slice index of the first FileReader with the passed filename returned from its Name method or -1 in case of no match.
func FileReaderNotExistsIndex ¶
func FileReaderNotExistsIndex(fileReades []FileReader, filename string) int
FileReaderNotExistsIndex returns the slice index of the first FileReader where the Exists method returned false or -1 in case of no match.
func FilesToNames ¶
FilesToNames returns a string slice with the names pars from the files
func FilesToPaths ¶
FilesToPaths returns the FileSystem specific paths of a slice of Files.
func FilesToURLs ¶
FilesToURLs returns the URLs of a slice of Files.
func IdenticalDirContents ¶
func IdenticalDirContents(ctx context.Context, dirA, dirB File, recursive bool) (identical bool, err error)
IdenticalDirContents returns true if the files in dirA and dirB are identical in size and content. If recursive is true, then directories will be considered too.
func IdenticalFileContents ¶
func IdenticalFileContents(ctx context.Context, files ...FileReader) (identical bool, err error)
IdenticalFileContents returns if the passed files have identical content. An error is returned if one of the files does not exist (ErrDoesNotExist) or if less than 2 files are passed. Compares files larger than 16MB via content hash to not allocate too much memory.
func IsRegistered ¶
func IsRegistered(fs FileSystem) bool
IsRegistered returns true if the file system is registered with its prefix.
func Move ¶
Move moves and/or renames source to destination. source and destination can be files or directories. If source is a directory, it will be moved with all its contents. If source and destination are using the same FileSystem, then FileSystem.Move will be used, else source will be copied recursively first to destination and then deleted.
func ReadAllContext ¶
ReadAllContext reads all data from r until EOF is reached, another error is returned, or the context got canceled. It is identical to io.ReadAll except that it can be canceled via a context.
func Register ¶
func Register(fs FileSystem) int
Register adds a file system or increments its reference count if it is already registered. The function returns the reference file system's reference count.
func Remove ¶
Remove removes all files with fileURIs. If a file does not exist, then it is skipped and not reported as error.
func RemoveErrDoesNotExist ¶
RemoveErrDoesNotExist returns nil if err wraps os.ErrNotExist, else err will be returned unchanged.
func RemoveFile ¶
RemoveFile removes a single file. It's just a wrapper for calling file.Remove(), useful mostly as callback for methods that list files to delete all files of a certain pattern. Or as a more elegant way to remove a file passed as string literal path:
fs.RemoveFile("/my/hardcoded.path")
func RemoveFiles ¶
RemoveFiles removes all files. If a file does not exist, then it is skipped and not reported as error.
func ServeFileHTTP ¶
func ServeFileHTTP(response http.ResponseWriter, request *http.Request, file FileReader, contentType ...string)
ServeFileHTTP serves the passed file with a Content-Type header via HTTP. If no contentType is passed then it will be deduced from the filename and if that fails from the content. A status code 404 error is returned if the file does not exist and a status code 500 error if there was any other error while reading it.
Uses http.ServeContent under the hood.
func ServeFileHTTPHandler ¶
func ServeFileHTTPHandler(file FileReader, contentType ...string) http.Handler
ServeFileHTTPHandler returns a http.Handler that serves the passed file with a Content-Type header via HTTP. If no contentType is passed then it will be deduced from the filename and if that fails from the content. A status code 404 error is returned if the file does not exist and a status code 500 error if there was any other error while reading it.
Uses http.ServeContent under the hood.
func SortByModified ¶
func SortByModified(files []File)
func SortByModifiedDirsFirst ¶
func SortByModifiedDirsFirst(files []File)
func SortByName ¶
func SortByName(files []File)
func SortByNameDirsFirst ¶
func SortByNameDirsFirst(files []File)
func SortByPath ¶
func SortByPath(files []File)
func SortBySize ¶
func SortBySize(files []File)
func Unregister ¶
func Unregister(fs FileSystem) int
Unregister a file system decrements its reference count and removes it when the reference count reaches 0. If the file system is not registered, -1 is returned.
Types ¶
type AppendFileSystem ¶
type AppendFileSystem interface { FileSystem Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error }
type AppendWriterFileSystem ¶
type AppendWriterFileSystem interface { FileSystem OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error) }
type ContentHashFunc ¶
ContentHashFunc is used tot return the string representation of a content hash by reading from an io.Reader until io.EOF or the context is cancelled.
var DefaultContentHash ContentHashFunc = fsimpl.DropboxContentHash
DefaultContentHash configures the default content hash function used by methods like File.ContentHash and FileReader.ContentHash.
func ContentHashFuncFrom ¶
func ContentHashFuncFrom(h hash.Hash) ContentHashFunc
ContentHashFuncFrom returns a ContentHashFunc that uses a standard hash.Hash implementation to return the hash sum as hex encoded string.
type CopyFileSystem ¶
type CopyFileSystem interface { FileSystem // CopyFile copies a single file. // buf must point to a []byte variable. // If that variable is initialized with a byte slice, then this slice will be used as buffer, // else a byte slice will be allocated for the variable. CopyFile(ctx context.Context, srcFile string, destFile string, buf *[]byte) error }
CopyFileSystem can be implemented by file systems that have native file copying functionality.
If a file system does not implement this interface then it's functionality will be emulated with other methods.
type ErrAlreadyExists ¶
type ErrAlreadyExists struct {
// contains filtered or unexported fields
}
ErrAlreadyExists is returned when a file already exists. It wraps os.ErrExist, check for this error type with:
errors.Is(err, os.ErrExist)
func NewErrAlreadyExists ¶
func NewErrAlreadyExists(file File) ErrAlreadyExists
NewErrAlreadyExists returns a new ErrAlreadyExists
func (ErrAlreadyExists) Error ¶
func (err ErrAlreadyExists) Error() string
func (ErrAlreadyExists) File ¶
func (err ErrAlreadyExists) File() File
File returns the file that already exists
type ErrDoesNotExist ¶
type ErrDoesNotExist struct {
// contains filtered or unexported fields
}
ErrDoesNotExist is returned when a file does not exist and wraps os.ErrNotExist. Check for this error type with:
errors.Is(err, os.ErrNotExist)
Implements http.Handler by responding with http.NotFound.
func NewErrDoesNotExist ¶
func NewErrDoesNotExist(file File) ErrDoesNotExist
NewErrDoesNotExist returns a new ErrDoesNotExist
func NewErrDoesNotExistFileReader ¶
func NewErrDoesNotExistFileReader(fileReader FileReader) ErrDoesNotExist
NewErrDoesNotExistFileReader returns an ErrDoesNotExist error for a FileReader.
func NewErrPathDoesNotExist ¶
func NewErrPathDoesNotExist(path string) ErrDoesNotExist
NewErrPathDoesNotExist returns an ErrDoesNotExist error for a file path.
func (ErrDoesNotExist) Error ¶
func (err ErrDoesNotExist) Error() string
Error implements the error interface
func (ErrDoesNotExist) File ¶
func (err ErrDoesNotExist) File() (file File, ok bool)
File returns the file that error concerns
func (ErrDoesNotExist) FileReader ¶
func (err ErrDoesNotExist) FileReader() (file FileReader, ok bool)
func (ErrDoesNotExist) ServeHTTP ¶
func (err ErrDoesNotExist) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ErrIsDirectory ¶
type ErrIsDirectory struct {
// contains filtered or unexported fields
}
ErrIsDirectory is returned when an operation is not possible because a file is a directory.
func NewErrIsDirectory ¶
func NewErrIsDirectory(file File) ErrIsDirectory
NewErrIsDirectory returns a new ErrIsDirectory
func (ErrIsDirectory) Error ¶
func (err ErrIsDirectory) Error() string
func (ErrIsDirectory) File ¶
func (err ErrIsDirectory) File() File
File returns the file that error concerns
type ErrIsNotDirectory ¶
type ErrIsNotDirectory struct {
// contains filtered or unexported fields
}
ErrIsNotDirectory is returned when an operation is not possible because a file is not a directory.
func NewErrIsNotDirectory ¶
func NewErrIsNotDirectory(file File) ErrIsNotDirectory
NewErrIsNotDirectory returns a new ErrIsNotDirectory
func (ErrIsNotDirectory) Error ¶
func (err ErrIsNotDirectory) Error() string
func (ErrIsNotDirectory) File ¶
func (err ErrIsNotDirectory) File() File
File returns the file that error concerns
type ErrPermission ¶
type ErrPermission struct {
// contains filtered or unexported fields
}
ErrPermission is returned when an operation lacks permissions on a file. It wraps os.ErrPermission. Check for this error type with:
errors.Is(err, os.ErrPermission)
Implements http.Handler by responding with 403 Forbidden.
func NewErrPermission ¶
func NewErrPermission(file File) ErrPermission
NewErrPermission returns a new ErrPermission
func (ErrPermission) Error ¶
func (err ErrPermission) Error() string
func (ErrPermission) File ¶
func (err ErrPermission) File() File
File returns the file that error concerns
func (ErrPermission) ServeHTTP ¶
func (err ErrPermission) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ErrUnsupported ¶
type ErrUnsupported struct {
// contains filtered or unexported fields
}
func NewErrUnsupported ¶
func NewErrUnsupported(fileSystem FileSystem, operation string) ErrUnsupported
NewErrUnsupported returns a new ErrUnsupported
func (ErrUnsupported) Error ¶
func (err ErrUnsupported) Error() string
func (ErrUnsupported) Unwrap ¶
func (ErrUnsupported) Unwrap() error
type Event ¶
type Event int
Event reported for watched files.
This is a bitmask and some systems may send multiple operations at once. Use the Has... methods to check if an event has a certain operation.
type ExistsFileSystem ¶
type ExistsFileSystem interface { FileSystem // Exists returns if a file exists and is accessible. // Depending on the FileSystem implementation, // this could be faster than using Stat. // Note that a file could exist but might not be accessible. Exists(filePath string) bool }
type File ¶
type File string
File is a local file system path or a complete URI. It is a string underneath, so string literals can be passed everywhere a File is expected. Marshalling functions that use reflection will also work out of the box when they detect that File is of kind reflect.String. File implements FileReader.
func CleanFilePath ¶
CleanFilePath returns a File from uri with cleaned path and a file system prefix
func CurrentWorkingDir ¶
func CurrentWorkingDir() File
CurrentWorkingDir returns the current working directory of the process. In case of an erorr, Exists() of the result File will return false.
func Executable ¶
func Executable() File
Executable returns a File for the executable that started the current process. It wraps os.Executable, see https://golang.ir/pkg/os/#Executable
func JoinCleanFilePath ¶
JoinCleanFilePath returns a File from joined and cleaned uriParts with a file system prefix
func MakeTempDir ¶
MakeTempDir makes and returns a new randomly named sub directory in TempDir(). Example:
tempDir, err := fs.MakeTempDir() if err != nil { return err } defer tempDir.RemoveRecursive() doThingsWith(tempDir)
func MustMakeTempDir ¶
func MustMakeTempDir() File
MustMakeTempDir makes and returns a new randomly named sub directory in TempDir(). It panics on errors. Example:
tempDir := fs.MustMakeTempDir() defer tempDir.RemoveRecursive() doThingsWith(tempDir)
func StringsToFiles ¶
StringsToFiles returns Files for the given fileURIs.
func TempFile ¶
TempFile returns a randomly named File with an optional extension in the temp directory of the operating system. The returned File does not exist yet, it's just a path.
func (File) AppendString ¶
func (File) CheckExists ¶
CheckExists return an ErrDoesNotExist error if the file does not exist or ErrEmptyPath if the file path is empty.
func (File) CheckIsDir ¶
CheckIsDir return an ErrDoesNotExist error if the file does not exist, ErrEmptyPath if the file path is empty, or ErrIsNotDirectory if a file exists, but is not a directory, or nil if the file is a directory.
func (File) ContentHash ¶
ContentHash returns the DefaultContentHash for the file. If the FileSystem implementation does not have this hash pre-computed, then the whole file is read to compute it. If the file is a directory, then an empty string will be returned.
func (File) ContentHashContext ¶
ContentHashContext returns the DefaultContentHash for the file. If the FileSystem implementation does not have this hash pre-computed, then the whole file is read to compute it. If the file is a directory, then an empty string will be returned.
func (File) DirAndName ¶
DirAndName returns the parent directory of filePath and the name with that directory of the last filePath element. If filePath is the root of the file systeme, then an empty string will be returned for name.
func (File) Ext ¶
Ext returns the extension of file name including the point, or an empty string.
Example:
File("image.png").Ext() == ".png" File("dir.with.ext/file").Ext() == "" File("dir.with.ext/file.ext").Ext() == ".ext"
func (File) ExtLower ¶
ExtLower returns the lower case extension of file name including the point, or an empty string. Example: File("Image.PNG").ExtLower() == ".png"
func (File) FileSystem ¶
func (file File) FileSystem() FileSystem
FileSystem returns the FileSystem of the File. Defaults to Local if not a complete URI, or Invalid for an empty path.
func (File) GobDecode ¶
GobDecode decodes a file name and content from gobBytes and writes the content to this file ignoring the decoded name. Implements encoding/gob.GobDecoder.
func (File) GobEncode ¶
GobEncode reads and gob encodes the file name and content, implementing encoding/gob.GobEncoder.
func (File) HasAbsPath ¶
HasAbsPath returns wether the file has an absolute path depending on the file system.
func (File) IsEmptyDir ¶
IsEmptyDir returns if file is an empty directory.
func (File) IsHidden ¶
IsHidden returns true if the filename begins with a dot, or if on Windows the hidden file attribute is set.
func (File) IsReadable ¶
IsReadable returns if the file exists and is readable.
func (File) IsSymbolicLink ¶
IsSymbolicLink returns if the file is a symbolic link Use LocalFileSystem.CreateSymbolicLink and LocalFileSystem.ReadSymbolicLink to handle symbolic links.
func (File) IsWriteable ¶
IsWriteable returns if the file exists and is writeable or in case it doesn't exist, if the parent directory exists and is writeable.
func (File) Join ¶
Join returns a new File with pathParts cleaned and joined to the current File's URI. Every element of pathParts is a subsequent directory or file that will be appended to the File URI with a path separator. The resulting URI path will be cleaned, removing relative directory names like "..".
func (File) Joinf ¶
Joinf returns a new File with smf.Sprintf(format, args...) cleaned and joined to the current File's URI. The resulting URI path will be cleaned, removing relative directory names like "..".
func (File) ListDir ¶
ListDir calls the passed callback function for every file and directory in dirPath. If any patterns are passed, then only files with a name that matches at least one of the patterns are returned.
func (File) ListDirChan ¶
ListDirChan returns listed files over a channel. An error or nil will returned from the error channel. The file channel will be closed after sending all files. If cancel is not nil and an error is sent to this channel, then the listing will be canceled and the error returned in the error channel returned by the method. See pipeline pattern: http://blog.golang.org/pipelines
func (File) ListDirContext ¶
func (file File) ListDirContext(ctx context.Context, callback func(File) error, patterns ...string) error
ListDirContext calls the passed callback function for every file and directory in dirPath. If any patterns are passed, then only files with a name that matches at least one of the patterns are returned.
func (File) ListDirInfo ¶
ListDirInfo calls the passed callback function for every file and directory in dirPath. If any patterns are passed, then only files with a name that matches at least one of the patterns are returned.
func (File) ListDirInfoContext ¶
func (file File) ListDirInfoContext(ctx context.Context, callback func(*FileInfo) error, patterns ...string) error
ListDirInfoContext calls the passed callback function for every file and directory in dirPath. If any patterns are passed, then only files with a name that matches at least one of the patterns are returned.
func (File) ListDirInfoRecursive ¶
ListDirInfoRecursive calls the passed callback function for every file (not directory) in dirPath recursing into all sub-directories. If any patterns are passed, then only files (not directories) with a name that matches at least one of the patterns are returned.
func (File) ListDirInfoRecursiveContext ¶
func (file File) ListDirInfoRecursiveContext(ctx context.Context, callback func(*FileInfo) error, patterns ...string) error
ListDirInfoRecursiveContext calls the passed callback function for every file (not directory) in dirPath recursing into all sub-directories. If any patterns are passed, then only files (not directories) with a name that matches at least one of the patterns are returned.
func (File) ListDirMax ¶
ListDirMax returns at most max files and directories in dirPath. A max value of -1 returns all files. If any patterns are passed, then only files or directories with a name that matches at least one of the patterns are returned.
func (File) ListDirMaxContext ¶
func (file File) ListDirMaxContext(ctx context.Context, max int, patterns ...string) (files []File, err error)
ListDirMaxContext returns at most max files and directories in dirPath. A max value of -1 returns all files. If any patterns are passed, then only files or directories with a name that matches at least one of the patterns are returned.
func (File) ListDirRecursive ¶
ListDirRecursive returns only files. patterns are only applied to files, not to directories
func (File) ListDirRecursiveChan ¶
func (file File) ListDirRecursiveChan(cancel <-chan error, patterns ...string) (<-chan File, <-chan error)
ListDirRecursiveChan returns listed files over a channel. An error or nil will returned from the error channel. The file channel will be closed after sending all files. If cancel is not nil and an error is sent to this channel, then the listing will be canceled and the error returned in the error channel returned by the method. See pipeline pattern: http://blog.golang.org/pipelines
func (File) ListDirRecursiveContext ¶
func (file File) ListDirRecursiveContext(ctx context.Context, callback func(File) error, patterns ...string) error
ListDirRecursiveContext returns only files. patterns are only applied to files, not to directories
func (File) ListDirRecursiveMax ¶
func (File) ListDirRecursiveMaxContext ¶
func (File) LocalPath ¶
LocalPath returns the cleaned local file-system path of the file, or an empty string if it is not on the local file system.
func (File) MakeAllDirs ¶
func (file File) MakeAllDirs(perm ...Permissions) error
MakeAllDirs creates all directories up to this one, does not return an error if the directories already exist
func (File) MakeDir ¶
func (file File) MakeDir(perm ...Permissions) error
MakeDir creates a directory if it does not exist yet. No error is returned if the directory already exists.
func (File) MoveTo ¶
MoveTo moves and/or renames the file to destination. destination can be a directory or file-path and can be on another FileSystem.
func (File) MustLocalPath ¶
MustLocalPath returns the cleaned local file-system path of the file, or panics if it is not on the local file system or an empty path.
func (File) Name ¶
Name returns the name part of the file path, which is usually the string after the last path Separator.
func (File) OpenAppendWriter ¶
func (file File) OpenAppendWriter(perm ...Permissions) (WriteCloser, error)
func (File) OpenReadSeeker ¶
func (file File) OpenReadSeeker() (ReadSeekCloser, error)
OpenReadSeeker opens the file and returns a ReadSeekCloser. If the FileSystem implementation doesn't support ReadSeekCloser, then the complete file is read into memory and wrapped with a ReadSeekCloser. Warning: this can use up a lot of memory for big files.
func (File) OpenReadWriter ¶
func (file File) OpenReadWriter(perm ...Permissions) (ReadWriteSeekCloser, error)
func (File) OpenReader ¶
func (file File) OpenReader() (ReadCloser, error)
OpenReader opens the file and returns a io/fs.File that has to be closed after reading
func (File) OpenWriter ¶
func (file File) OpenWriter(perm ...Permissions) (WriteCloser, error)
func (File) ParseRawURI ¶
func (file File) ParseRawURI() (fs FileSystem, fsPath string)
ParseRawURI returns a FileSystem for the passed URI and the path component within that file system. Returns the local file system if no other file system could be identified.
func (File) Path ¶
Path returns the cleaned path of the file. It may differ from the string value of File because it will be cleaned depending on the FileSystem
func (File) PathWithSlashes ¶
PathWithSlashes returns the cleaned path of the file always using the slash '/' as separator. It may differ from the string value of File because it will be cleaned depending on the FileSystem
func (File) Permissions ¶
func (file File) Permissions() Permissions
func (File) ReadAllContentHash ¶
ReadAllContentHash reads and returns all bytes of the file together with the DefaultContentHash.
func (File) ReadAllContext ¶
ReadAllContext reads and returns all bytes of the file
func (File) ReadAllString ¶
ReadAllString reads the complete file and returns the content as string.
func (File) ReadAllStringContext ¶
ReadAllStringContext reads the complete file and returns the content as string.
func (File) ReadFrom ¶
ReadFrom implements the io.ReaderFrom interface, the file is writter with the existing permissions if it exists, or with the default write permissions if it does not exist yet.
func (File) RemoveDirContents ¶
RemoveDirContents deletes all files in this directory, or if given all files with patterns from the this directory.
func (File) RemoveDirContentsContext ¶
RemoveDirContentsContext deletes all files in this directory, or if given all files with patterns from the this directory.
func (File) RemoveDirContentsRecursive ¶
RemoveDirContentsRecursive deletes all files and directories in this directory recursively.
func (File) RemoveDirContentsRecursiveContext ¶
RemoveDirContentsRecursiveContext deletes all files and directories in this directory recursively.
func (File) RemoveRecursive ¶
RemoveRecursive deletes the file or if it's a directory the complete recursive directory tree.
func (File) RemoveRecursiveContext ¶
RemoveRecursiveContext deletes the file or if it's a directory the complete recursive directory tree.
func (File) Rename ¶
Rename changes the name of a file where newName is the name part after file.Dir(). Note: this does not move the file like in other rename implementations, it only changes the name of the file within its directdory.
func (File) Renamef ¶
Renamef changes the name of a file where fmt.Sprintf(newNameFormat, args...) is the name part after file.Dir(). Note: this does not move the file like in other rename implementations, it only changes the name of the file within its directdory.
func (File) SetPermissions ¶
func (file File) SetPermissions(perm Permissions) error
func (File) StdDirEntry ¶
func (file File) StdDirEntry() StdDirEntry
StdDirEntry wraps the file as a StdDirEntry struct that implements the io/fs.DirEntry interface from the standard library for a File.
func (File) StdFS ¶
StdFS wraps the file as a StdFS struct that implements the io/fs.FS interface of the standard library for a File.
StdFS implements the following interfaces:
- io/fs.FS
- io/fs.SubFS
- io/fs.StatFS
- io/fs.GlobFS
- io/fs.ReadDirFS
- io/fs.ReadFileFS
func (File) String ¶
String returns information about the File and its FileSystem. String implements the fmt.Stringer interface.
func (File) ToAbsPath ¶
ToAbsPath returns the file with an absolute path depending on the file system.
func (File) Touch ¶
func (file File) Touch(perm ...Permissions) error
func (File) TrimExt ¶
TrimExt returns a File with a path where the extension is removed. Note that this does not rename an actual existing file.
func (File) VolumeName ¶
VolumeName returns the name of the volume at the beginning of the file path, or an empty string if the path has no volume. A volume is for example "C:" on Windows
func (File) Watch ¶
Watch a file or directory for changes. If the file describes a directory then changes directly within it will be reported. This does not apply changes in deeper recursive sub-directories.
It is valid to watch a file with multiple callbacks, calling the returned cancel function will cancel a particular watch.
func (File) WriteAllContext ¶
func (File) WriteAllString ¶
func (file File) WriteAllString(str string, perm ...Permissions) error
func (File) WriteAllStringContext ¶
func (File) WriteJSON ¶
WriteJSON mashalles input to JSON and writes it as the file. Any indent arguments will be concanated and used as JSON line indentation.
type FileInfo ¶
type FileInfo struct { File File Name string Exists bool IsDir bool IsRegular bool IsHidden bool Size int64 Modified time.Time Permissions Permissions }
FileInfo is a snapshot of a file's stat information. In comparison to io/fs.FileInfo it's not an interface but a struct with public fields.
func NewFileInfo ¶
NewFileInfo returns a FileInfo using the data from an io/fs.FileInfo as snapshot of an existing file. Use NewNonExistingFileInfo to get a FileInfo for non existing file.
func NewNonExistingFileInfo ¶
NewNonExistingFileInfo returns a FileInfo for a potentially non existing file. FileInfo.Exists will be false, but the file may exist at any point of time. IsHidden will be true if the name starts with a dot.
func (*FileInfo) StdFileInfo ¶
StdFileInfo returns an io/fs.FileInfo wrapper for the data stored in the FileInfo struct.
type FileInfoCache ¶
type FileInfoCache struct {
// contains filtered or unexported fields
}
FileInfoCache is a cache with timeout for FileInfo data.
func NewFileInfoCache ¶
func NewFileInfoCache(timeout time.Duration) *FileInfoCache
NewFileInfoCache returns a new FileInfoCache with timeout, or nil if timeout is zero. It is valid to call the methods of FileInfoCache for a nil pointer.
func (*FileInfoCache) Delete ¶
func (cache *FileInfoCache) Delete(path string)
Delete deletes the FileInfo with path if was cached.
func (*FileInfoCache) Get ¶
func (cache *FileInfoCache) Get(path string) (info *FileInfo, ok bool)
Get returns the FileInfo for a path or nil and false if there is no FileInfo for the path or the FileInfo has timed out.
func (*FileInfoCache) Put ¶
func (cache *FileInfoCache) Put(path string, info *FileInfo)
Put puts or updates a FileInfo for a path.
type FileReader ¶
type FileReader interface { // String returns the name and meta information for the FileReader. String() string // Name returns the name of the file Name() string // Ext returns the extension of file name including the point, or an empty string. Ext() string // LocalPath returns the cleaned local file-system path of the file backing the FileReader, // or an empty string if the FileReader is not backed by a local file. LocalPath() string // Size returns the size of the file Size() int64 // Exists returns if file or data for the implementation exists Exists() bool // CheckExists return an ErrDoesNotExist error // if the file does not exist. CheckExists() error // ContentHash returns the DefaultContentHash for the file. ContentHash() (string, error) // ContentHashContext returns the DefaultContentHash for the file. ContentHashContext(ctx context.Context) (string, error) // ReadAll reads and returns all bytes of the file ReadAll() (data []byte, err error) // ReadAllContext reads and returns all bytes of the file ReadAllContext(context.Context) (data []byte, err error) // ReadAllContentHash reads and returns all bytes of the file // together with the DefaultContentHash. ReadAllContentHash(context.Context) (data []byte, hash string, err error) // ReadAllString reads the complete file and returns the content as string. ReadAllString() (string, error) // ReadAllStringContext reads the complete file and returns the content as string. ReadAllStringContext(context.Context) (string, error) // WriteTo implements the io.WriterTo interface WriteTo(writer io.Writer) (n int64, err error) // OpenReader opens the file and returns a ReadCloser that has to be closed after reading OpenReader() (ReadCloser, error) // OpenReadSeeker opens the file and returns a ReadSeekCloser. // Use OpenReader if seeking is not necessary because implementations // may need additional buffering to support seeking or not support it at all. OpenReadSeeker() (ReadSeekCloser, error) // ReadJSON reads and unmarshalles the JSON content of the file to output. ReadJSON(ctx context.Context, output any) error // ReadXML reads and unmarshalles the XML content of the file to output. ReadXML(ctx context.Context, output any) error // GobEncode reads and gob encodes the file name and content, // implementing encoding/gob.GobEncoder. GobEncode() ([]byte, error) }
func FileReaderWithName ¶
func FileReaderWithName(fileReader FileReader, name string) FileReader
FileReaderWithName returns a new FileReader that wraps the passed fileReader, but the Name() method returns the passed name instead of name of the wrapped fileReader.
func FilesToFileReaders ¶
func FilesToFileReaders(files []File) []FileReader
FilesToFileReaders converts a slice of File to a slice of FileReader
func MemFilesAsFileReaders ¶
func MemFilesAsFileReaders(memFiles []MemFile) []FileReader
MemFilesAsFileReaders converts []MemFile to []FileReader
func StringsToFileReaders ¶
func StringsToFileReaders(fileURIs []string) []FileReader
StringsToFileReaders returns FileReaders for the given fileURIs.
type FileSystem ¶
type FileSystem interface { ReadableWritable() (readable, writable bool) // RootDir returns the file system root directory RootDir() File // ID returns a unique identifyer for the FileSystem ID() (string, error) Prefix() string // Name returns the name of the FileSystem implementation Name() string // String returns a descriptive string for the FileSystem implementation String() string // URL returns a full URL wich is Prefix() + cleanPath. // Note that the passed cleanPath will not be cleaned // by the FileSystem implementation. URL(cleanPath string) string // CleanPathFromURI returns the clean path part of an URI // specific to the implementation of the FileSystem. // It's the inverse of the URL method. CleanPathFromURI(uri string) string // JoinCleanFile joins the file system prefix with uriParts // into a File with clean path and prefix JoinCleanFile(uriParts ...string) File // JoinCleanPath joins the uriParts into a cleaned path // of the file system style without the file system prefix JoinCleanPath(uriParts ...string) string // SplitPath returns all Separator() delimited components of filePath // without the file system prefix. SplitPath(filePath string) []string // Separator for paths of the file system Separator() string // IsAbsPath indicates if the passed filePath is absolute IsAbsPath(filePath string) bool // AbsPath returns the passe filePath in absolute form AbsPath(filePath string) string // MatchAnyPattern returns true if name matches any of patterns, // or if len(patterns) == 0. // The match per pattern works like path.Match or filepath.Match MatchAnyPattern(name string, patterns []string) (bool, error) // SplitDirAndName returns the parent directory of filePath and the name with that directory of the last filePath element. // If filePath is the root of the file systeme, then an empty string will be returned for name. SplitDirAndName(filePath string) (dir, name string) Stat(filePath string) (iofs.FileInfo, error) // IsHidden returns if a file is hidden depending // on the definition of hidden files of the file system, // but it will always return true if the name of the file starts with a dot. IsHidden(filePath string) bool // TODO // IsSymbolicLink returns if a file is a symbolic link IsSymbolicLink(filePath string) bool // TODO // ListDirInfo calls the passed callback function for every file and directory in dirPath. // If any patterns are passed, then only files or directores with a name that matches // at least one of the patterns are returned. ListDirInfo(ctx context.Context, dirPath string, callback func(*FileInfo) error, patterns []string) error MakeDir(dirPath string, perm []Permissions) error OpenReader(filePath string) (ReadCloser, error) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error) // Remove deletes the file. Remove(filePath string) error // Close the file system or do nothing if it is not closable Close() error }
FileSystem is an interface that has to be implemented for a file system to be accessable via this package.
func GetFileSystem ¶
func GetFileSystem(uriParts ...string) FileSystem
GetFileSystem returns a FileSystem for the passed URI. Returns the local file system if no other file system could be identified. The URI can be passed as parts that will be joined according to the file system.
func GetFileSystemByPrefixOrNil ¶
func GetFileSystemByPrefixOrNil(prefix string) FileSystem
GetFileSystemByPrefixOrNil returns the file system registered with the passed prefix, or nil if it can't be found.
func ParseRawURI ¶
func ParseRawURI(uri string) (fs FileSystem, fsPath string)
ParseRawURI returns a FileSystem for the passed URI and the path component within that file system. Returns the local file system if no other file system could be identified.
func RegisteredFileSystems ¶
func RegisteredFileSystems() []FileSystem
RegisteredFileSystems returns the registered file systems sorted by their prefix.
type GroupFileSystem ¶
type InvalidFileSystem ¶
type InvalidFileSystem string
InvalidFileSystem is a file system where all operations are invalid. A File with an empty path defaults to this FS.
The underlying string value is the optional name of the file system and will be added to the URI prefix. It can be used to register different dummy file systems for debugging or testing purposes.
var ( // Local is the local file system Local = &LocalFileSystem{ DefaultCreatePermissions: UserAndGroupReadWrite, DefaultCreateDirPermissions: UserAndGroupReadWrite, } Invalid InvalidFileSystem )
func (InvalidFileSystem) AbsPath ¶
func (fs InvalidFileSystem) AbsPath(filePath string) string
func (InvalidFileSystem) Append ¶
func (InvalidFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error
func (InvalidFileSystem) CleanPathFromURI ¶
func (fs InvalidFileSystem) CleanPathFromURI(uri string) string
func (InvalidFileSystem) Close ¶
func (InvalidFileSystem) Close() error
func (InvalidFileSystem) Exists ¶
func (InvalidFileSystem) Exists(filePath string) bool
func (InvalidFileSystem) ID ¶
func (fs InvalidFileSystem) ID() (string, error)
func (InvalidFileSystem) IsAbsPath ¶
func (InvalidFileSystem) IsAbsPath(filePath string) bool
func (InvalidFileSystem) IsHidden ¶
func (InvalidFileSystem) IsHidden(filePath string) bool
func (InvalidFileSystem) IsSymbolicLink ¶
func (InvalidFileSystem) IsSymbolicLink(filePath string) bool
func (InvalidFileSystem) JoinCleanFile ¶
func (fs InvalidFileSystem) JoinCleanFile(uri ...string) File
func (InvalidFileSystem) JoinCleanPath ¶
func (fs InvalidFileSystem) JoinCleanPath(uriParts ...string) string
func (InvalidFileSystem) ListDirInfo ¶
func (InvalidFileSystem) ListDirInfoRecursive ¶
func (InvalidFileSystem) ListDirMax ¶
func (InvalidFileSystem) MakeAllDirs ¶
func (InvalidFileSystem) MakeAllDirs(dirPath string, perm []Permissions) error
func (InvalidFileSystem) MakeDir ¶
func (InvalidFileSystem) MakeDir(dirPath string, perm []Permissions) error
func (InvalidFileSystem) MatchAnyPattern ¶
func (InvalidFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error)
func (InvalidFileSystem) Move ¶
func (InvalidFileSystem) Move(filePath string, destPath string) error
func (InvalidFileSystem) Name ¶
func (fs InvalidFileSystem) Name() string
func (InvalidFileSystem) OpenAppendWriter ¶
func (InvalidFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (InvalidFileSystem) OpenReadWriter ¶
func (InvalidFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
func (InvalidFileSystem) OpenReader ¶
func (InvalidFileSystem) OpenReader(filePath string) (ReadCloser, error)
func (InvalidFileSystem) OpenWriter ¶
func (InvalidFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (InvalidFileSystem) Prefix ¶
func (fs InvalidFileSystem) Prefix() string
func (InvalidFileSystem) ReadableWritable ¶
func (InvalidFileSystem) ReadableWritable() (readable, writable bool)
func (InvalidFileSystem) Remove ¶
func (InvalidFileSystem) Remove(filePath string) error
func (InvalidFileSystem) Rename ¶
func (InvalidFileSystem) Rename(filePath string, newName string) (string, error)
func (InvalidFileSystem) RootDir ¶
func (InvalidFileSystem) RootDir() File
func (InvalidFileSystem) Separator ¶
func (InvalidFileSystem) Separator() string
func (InvalidFileSystem) SetGroup ¶
func (InvalidFileSystem) SetGroup(filePath string, group string) error
func (InvalidFileSystem) SetPermissions ¶
func (InvalidFileSystem) SetPermissions(filePath string, perm Permissions) error
func (InvalidFileSystem) SetUser ¶
func (InvalidFileSystem) SetUser(filePath string, user string) error
func (InvalidFileSystem) SplitDirAndName ¶
func (fs InvalidFileSystem) SplitDirAndName(filePath string) (dir, name string)
func (InvalidFileSystem) SplitPath ¶
func (fs InvalidFileSystem) SplitPath(filePath string) []string
func (InvalidFileSystem) Stat ¶
func (InvalidFileSystem) Stat(filePath string) (iofs.FileInfo, error)
func (InvalidFileSystem) String ¶
func (fs InvalidFileSystem) String() string
func (InvalidFileSystem) Touch ¶
func (InvalidFileSystem) Touch(filePath string, perm []Permissions) error
func (InvalidFileSystem) Truncate ¶
func (InvalidFileSystem) Truncate(filePath string, size int64) error
func (InvalidFileSystem) URL ¶
func (fs InvalidFileSystem) URL(cleanPath string) string
func (InvalidFileSystem) VolumeName ¶
func (InvalidFileSystem) VolumeName(filePath string) string
func (InvalidFileSystem) WriteAll ¶
func (InvalidFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error
type ListDirMaxFileSystem ¶
type ListDirMaxFileSystem interface { // ListDirMax returns at most max files and directories in dirPath. // A max value of -1 returns all files. // If any patterns are passed, then only files or directories with a name that matches // at least one of the patterns are returned. ListDirMax(ctx context.Context, dirPath string, max int, patterns []string) ([]File, error) }
type ListDirRecursiveFileSystem ¶
type ListDirRecursiveFileSystem interface { // ListDirInfoRecursive calls the passed callback function for every file (not directory) in dirPath // recursing into all sub-directories. // If any patterns are passed, then only files (not directories) with a name that matches // at least one of the patterns are returned. ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(*FileInfo) error, patterns []string) error }
type LocalFileSystem ¶
type LocalFileSystem struct { // DefaultCreatePermissions are the default file permissions used for creating new files DefaultCreatePermissions Permissions // DefaultCreateDirPermissions are the default file permissions used for creating new directories DefaultCreateDirPermissions Permissions WatchEventLogger Logger WatchErrorLogger Logger // contains filtered or unexported fields }
LocalFileSystem implements FileSystem for the local file system.
func (*LocalFileSystem) AbsPath ¶
func (local *LocalFileSystem) AbsPath(filePath string) string
func (*LocalFileSystem) Append ¶
func (local *LocalFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error
func (*LocalFileSystem) CleanPathFromURI ¶
func (local *LocalFileSystem) CleanPathFromURI(uri string) string
func (*LocalFileSystem) Close ¶
func (*LocalFileSystem) Close() error
func (*LocalFileSystem) CreateSymbolicLink ¶
func (local *LocalFileSystem) CreateSymbolicLink(oldFile, newFile File) error
func (*LocalFileSystem) Group ¶
func (local *LocalFileSystem) Group(filePath string) (string, error)
func (*LocalFileSystem) ID ¶
func (local *LocalFileSystem) ID() (string, error)
func (*LocalFileSystem) IsAbsPath ¶
func (local *LocalFileSystem) IsAbsPath(filePath string) bool
func (*LocalFileSystem) IsHidden ¶
func (local *LocalFileSystem) IsHidden(filePath string) bool
func (*LocalFileSystem) IsSymbolicLink ¶
func (local *LocalFileSystem) IsSymbolicLink(filePath string) bool
func (*LocalFileSystem) JoinCleanFile ¶
func (local *LocalFileSystem) JoinCleanFile(uri ...string) File
func (*LocalFileSystem) JoinCleanPath ¶
func (local *LocalFileSystem) JoinCleanPath(uriParts ...string) string
func (*LocalFileSystem) ListDirInfo ¶
func (*LocalFileSystem) ListDirMax ¶
func (*LocalFileSystem) MakeAllDirs ¶
func (local *LocalFileSystem) MakeAllDirs(dirPath string, perm []Permissions) error
func (*LocalFileSystem) MakeDir ¶
func (local *LocalFileSystem) MakeDir(dirPath string, perm []Permissions) error
func (*LocalFileSystem) MatchAnyPattern ¶
func (local *LocalFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error)
MatchAnyPattern returns true if name matches any of patterns, or if len(patterns) == 0. The match per pattern works like path.Match or filepath.Match
func (*LocalFileSystem) Move ¶
func (local *LocalFileSystem) Move(filePath string, destPath string) error
func (*LocalFileSystem) Name ¶
func (local *LocalFileSystem) Name() string
func (*LocalFileSystem) OpenAppendWriter ¶
func (local *LocalFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (*LocalFileSystem) OpenReadWriter ¶
func (local *LocalFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
func (*LocalFileSystem) OpenReader ¶
func (local *LocalFileSystem) OpenReader(filePath string) (ReadCloser, error)
func (*LocalFileSystem) OpenWriter ¶
func (local *LocalFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (*LocalFileSystem) Prefix ¶
func (local *LocalFileSystem) Prefix() string
func (*LocalFileSystem) ReadSymbolicLink ¶
func (local *LocalFileSystem) ReadSymbolicLink(file File) (linked File, err error)
func (*LocalFileSystem) ReadableWritable ¶
func (local *LocalFileSystem) ReadableWritable() (readable, writable bool)
func (*LocalFileSystem) Remove ¶
func (local *LocalFileSystem) Remove(filePath string) error
func (*LocalFileSystem) Rename ¶
func (local *LocalFileSystem) Rename(filePath string, newName string) (newPath string, err error)
func (*LocalFileSystem) RootDir ¶
func (local *LocalFileSystem) RootDir() File
func (*LocalFileSystem) Separator ¶
func (local *LocalFileSystem) Separator() string
func (*LocalFileSystem) SetGroup ¶
func (local *LocalFileSystem) SetGroup(filePath string, group string) error
func (*LocalFileSystem) SetPermissions ¶
func (local *LocalFileSystem) SetPermissions(filePath string, perm Permissions) error
func (*LocalFileSystem) SetUser ¶
func (local *LocalFileSystem) SetUser(filePath string, username string) error
func (*LocalFileSystem) SplitDirAndName ¶
func (*LocalFileSystem) SplitDirAndName(filePath string) (dir, name string)
func (*LocalFileSystem) SplitPath ¶
func (local *LocalFileSystem) SplitPath(filePath string) []string
func (*LocalFileSystem) Stat ¶
func (local *LocalFileSystem) Stat(filePath string) (iofs.FileInfo, error)
func (*LocalFileSystem) String ¶
func (local *LocalFileSystem) String() string
String implements the fmt.Stringer interface.
func (*LocalFileSystem) Touch ¶
func (local *LocalFileSystem) Touch(filePath string, perm []Permissions) error
func (*LocalFileSystem) Truncate ¶
func (local *LocalFileSystem) Truncate(filePath string, newSize int64) error
func (*LocalFileSystem) URL ¶
func (local *LocalFileSystem) URL(cleanPath string) string
func (*LocalFileSystem) VolumeName ¶
func (local *LocalFileSystem) VolumeName(filePath string) string
func (*LocalFileSystem) WriteAll ¶
func (local *LocalFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error
type LoggerFunc ¶
LoggerFunc implements Logger as higher order function
func (LoggerFunc) Printf ¶
func (f LoggerFunc) Printf(format string, args ...any)
type MakeAllDirsFileSystem ¶
type MakeAllDirsFileSystem interface { FileSystem MakeAllDirs(dirPath string, perm []Permissions) error }
type MemFile ¶
MemFile implements FileReader with a filename and an in memory byte slice. It exposes FileName and FileData as exported struct fields to emphasize its simple nature as just an wrapper around a name and some bytes.
As a small an simple struct MemFile is usually passed by value. This is why NewMemFile does not return a pointer.
Note that the ReadAll and ReadAllContext methods return FileData directly without copying it to optimized performance. So be careful when modifying the FileData bytes of a MemFile.
MemFile implements the following interfaces:
- FileReader
- io.Writer
- io.WriterTo
- io.ReaderAt
- json.Marshaler
- json.Unmarshaler
- gob.GobEncoder
- gob.GobDecoder
- fmt.Stringer
func NewMemFile ¶
NewMemFile returns a new MemFile
func ReadAllMemFile ¶
ReadAllMemFile returns a new MemFile with the data from ReadAllContext(r) and the passed name. It reads all data from r until EOF is reached, another error is returned, or the context got canceled.
func ReadMemFile ¶
func ReadMemFile(ctx context.Context, fileReader FileReader) (MemFile, error)
ReadMemFile returns a new MemFile with name and data from fileReader. If the passed fileReader is a MemFile then its FileData is used directly without copying it.
func ReadMemFileRename ¶
ReadMemFileRename returns a new MemFile with the data from fileReader and the passed name. If the passed fileReader is a MemFile then its FileData is used directly without copying it.
func UnzipToMemFiles ¶
func UnzipToMemFiles(ctx context.Context, zipFile FileReader) ([]MemFile, error)
UnzipToMemFiles unzips the passed zipFile as MemFiles.
func (MemFile) CheckExists ¶
CheckExists return an ErrDoesNotExist error if the file does not exist.
func (MemFile) ContentHash ¶
ContentHash returns the DefaultContentHash for the file.
func (MemFile) ContentHashContext ¶
ContentHashContext returns the DefaultContentHash for the file.
func (MemFile) Exists ¶
Exists returns true if the MemFile has non empty FileName. It's valid to call this method on a nil pointer, will return false in this case.
func (MemFile) Ext ¶
Ext returns the extension of file name including the point, or an empty string.
func (*MemFile) GobDecode ¶
GobDecode decodes gobBytes file name and content, implementing encoding/gob.GobDecoder.
func (MemFile) GobEncode ¶
GobEncode gob encodes the file name and content, implementing encoding/gob.GobEncoder.
func (MemFile) Name ¶
Name returns the name of the file. If FileName contains a slash or backslash then only the part after it will be returned.
func (MemFile) OpenReadSeeker ¶
func (f MemFile) OpenReadSeeker() (ReadSeekCloser, error)
OpenReadSeeker opens the file and returns a ReadSeekCloser. Use OpenReader if seeking is not necessary because implementations may need additional buffering to support seeking or not support it at all.
func (MemFile) OpenReader ¶
func (f MemFile) OpenReader() (ReadCloser, error)
OpenReader opens the file and returns a io/fs.File that has to be closed after reading
func (MemFile) ReadAllContentHash ¶
ReadAllContentHash returns the FileData without copying it together with the DefaultContentHash.
func (MemFile) ReadAllContext ¶
ReadAllContext returns the FileData without copying it.
func (MemFile) ReadAllString ¶
ReadAllString returns the FileData as string.
func (MemFile) ReadAllStringContext ¶
ReadAllStringContext returns the FileData as string.
func (MemFile) ReadAt ¶
ReadAt reads len(p) bytes into p starting at offset off in the underlying input source. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
When ReadAt returns n < len(p), it returns a non-nil error explaining why more bytes were not returned. In this respect, ReadAt is stricter than Read.
If the n = len(p) bytes returned by ReadAt are at the end of the input source, ReadAt returns err == nil.
Clients of ReadAt can execute parallel ReadAt calls on the same input source.
ReadAt implements the interface io.ReaderAt.
func (MemFile) String ¶
String returns the name and meta information for the FileReader. String implements the fmt.Stringer interface.
type MemFileSystem ¶
type MemFileSystem struct {
// contains filtered or unexported fields
}
MemFileSystem is a fully featured thread-safe file system living in random access memory.
Usefull as mock file system for tests or caching of slow file systems.
func NewMemFileSystem ¶
func NewMemFileSystem(separator string, initialFiles ...MemFile) (*MemFileSystem, error)
func (*MemFileSystem) AbsPath ¶
func (fs *MemFileSystem) AbsPath(filePath string) string
func (*MemFileSystem) AddMemFile ¶
AddMemFile adds a MemFile to the file system with the given modified time. The MemFile.FileName can be a path with the path separator of the MemFileSystem, in which case all directories of the path are created.
func (*MemFileSystem) Append ¶
func (fs *MemFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error
func (*MemFileSystem) CleanPathFromURI ¶
func (fs *MemFileSystem) CleanPathFromURI(uri string) string
func (*MemFileSystem) Clear ¶
func (fs *MemFileSystem) Clear()
func (*MemFileSystem) Close ¶
func (fs *MemFileSystem) Close() error
func (*MemFileSystem) Exists ¶
func (fs *MemFileSystem) Exists(filePath string) bool
func (*MemFileSystem) ID ¶
func (fs *MemFileSystem) ID() (string, error)
func (*MemFileSystem) IsAbsPath ¶
func (fs *MemFileSystem) IsAbsPath(filePath string) bool
func (*MemFileSystem) IsHidden ¶
func (*MemFileSystem) IsHidden(filePath string) bool
func (*MemFileSystem) IsSymbolicLink ¶
func (*MemFileSystem) IsSymbolicLink(filePath string) bool
func (*MemFileSystem) JoinCleanFile ¶
func (fs *MemFileSystem) JoinCleanFile(uri ...string) File
func (*MemFileSystem) JoinCleanPath ¶
func (fs *MemFileSystem) JoinCleanPath(uriParts ...string) string
func (*MemFileSystem) ListDirInfo ¶
func (*MemFileSystem) MakeAllDirs ¶
func (fs *MemFileSystem) MakeAllDirs(dirPath string, perm []Permissions) error
func (*MemFileSystem) MakeDir ¶
func (fs *MemFileSystem) MakeDir(dirPath string, perm []Permissions) error
func (*MemFileSystem) MatchAnyPattern ¶
func (*MemFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error)
func (*MemFileSystem) Name ¶
func (*MemFileSystem) Name() string
func (*MemFileSystem) OpenAppendWriter ¶
func (fs *MemFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (*MemFileSystem) OpenReadWriter ¶
func (fs *MemFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
func (*MemFileSystem) OpenReader ¶
func (fs *MemFileSystem) OpenReader(filePath string) (iofs.File, error)
func (*MemFileSystem) OpenWriter ¶
func (fs *MemFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (*MemFileSystem) Prefix ¶
func (fs *MemFileSystem) Prefix() string
func (*MemFileSystem) ReadableWritable ¶
func (fs *MemFileSystem) ReadableWritable() (readable, writable bool)
func (*MemFileSystem) Remove ¶
func (fs *MemFileSystem) Remove(filePath string) error
func (*MemFileSystem) Rename ¶
func (fs *MemFileSystem) Rename(filePath string, newName string) (string, error)
func (*MemFileSystem) RootDir ¶
func (fs *MemFileSystem) RootDir() File
func (*MemFileSystem) Separator ¶
func (fs *MemFileSystem) Separator() string
func (*MemFileSystem) SetReadOnly ¶
func (fs *MemFileSystem) SetReadOnly(readOnly bool)
func (*MemFileSystem) SplitDirAndName ¶
func (fs *MemFileSystem) SplitDirAndName(filePath string) (dir, name string)
func (*MemFileSystem) SplitPath ¶
func (fs *MemFileSystem) SplitPath(filePath string) []string
func (*MemFileSystem) String ¶
func (fs *MemFileSystem) String() string
func (*MemFileSystem) Touch ¶
func (fs *MemFileSystem) Touch(filePath string, perm []Permissions) error
func (*MemFileSystem) Truncate ¶
func (fs *MemFileSystem) Truncate(filePath string, newSize int64) error
func (*MemFileSystem) URL ¶
func (fs *MemFileSystem) URL(cleanPath string) string
func (*MemFileSystem) Volume ¶
func (fs *MemFileSystem) Volume() string
func (*MemFileSystem) VolumeName ¶
func (fs *MemFileSystem) VolumeName(filePath string) string
func (*MemFileSystem) WithID ¶
func (fs *MemFileSystem) WithID(id string) *MemFileSystem
func (*MemFileSystem) WithVolume ¶
func (fs *MemFileSystem) WithVolume(volume string) *MemFileSystem
func (*MemFileSystem) WriteAll ¶
func (fs *MemFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error
type MoveFileSystem ¶
type MoveFileSystem interface { FileSystem // Move moves and/or renames the file to destination. // destination can be a directory or file-path. // If successful, this also changes the path of this File's implementation. Move(filePath string, destinationPath string) error }
MoveFileSystem can be implemented by file systems that have native file moving functionality.
If a file system does not implement this interface then it's functionality will be emulated with other methods.
type Permissions ¶
type Permissions int
Permissions for a file, follows the Unix/os.FileMode bit schema.
var ( NoPermissions Permissions = 0 UserExecute Permissions = 0100 UserWrite Permissions = 0200 UserRead Permissions = 0400 UserReadWrite Permissions = UserRead | UserWrite UserReadWriteExecute Permissions = UserRead | UserWrite | UserExecute GroupExecute Permissions = 0010 GroupWrite Permissions = 0020 GroupRead Permissions = 0040 GroupReadWrite Permissions = GroupRead | GroupWrite GroupReadWriteExecute Permissions = GroupRead | GroupWrite | GroupExecute UserAndGroupRead Permissions = UserRead | GroupRead UserAndGroupReadWrite Permissions = UserReadWrite | GroupReadWrite UserAndGroupReadWriteExecute Permissions = UserReadWriteExecute | GroupReadWriteExecute OthersExecute Permissions = 0001 OthersWrite Permissions = 0002 OthersRead Permissions = 0004 OthersReadWrite Permissions = OthersRead | OthersWrite OthersReadWriteExecute Permissions = OthersRead | OthersWrite | OthersExecute AllRead = UserRead | GroupRead | OthersRead AllWrite = UserWrite | GroupWrite | OthersWrite AllExecute = UserExecute | GroupExecute | OthersExecute AllReadWrite = UserReadWrite | GroupReadWrite | OthersReadWrite )
func JoinPermissions ¶
func JoinPermissions(perms []Permissions, defaultPerm Permissions) (result Permissions)
func PermissionsFromStdFileInfo ¶
func PermissionsFromStdFileInfo(info iofs.FileInfo) Permissions
func (Permissions) Can ¶
func (perm Permissions) Can(p Permissions) bool
func (Permissions) CanAllExecute ¶
func (perm Permissions) CanAllExecute() bool
func (Permissions) CanAllRead ¶
func (perm Permissions) CanAllRead() bool
func (Permissions) CanAllReadWrite ¶
func (perm Permissions) CanAllReadWrite() bool
func (Permissions) CanAllWrite ¶
func (perm Permissions) CanAllWrite() bool
func (Permissions) CanGroupExecute ¶
func (perm Permissions) CanGroupExecute() bool
func (Permissions) CanGroupRead ¶
func (perm Permissions) CanGroupRead() bool
func (Permissions) CanGroupReadWrite ¶
func (perm Permissions) CanGroupReadWrite() bool
func (Permissions) CanGroupWrite ¶
func (perm Permissions) CanGroupWrite() bool
func (Permissions) CanOthersExecute ¶
func (perm Permissions) CanOthersExecute() bool
func (Permissions) CanOthersRead ¶
func (perm Permissions) CanOthersRead() bool
func (Permissions) CanOthersReadWrite ¶
func (perm Permissions) CanOthersReadWrite() bool
func (Permissions) CanOthersWrite ¶
func (perm Permissions) CanOthersWrite() bool
func (Permissions) CanUserAndGroupRead ¶
func (perm Permissions) CanUserAndGroupRead() bool
func (Permissions) CanUserAndGroupReadWrite ¶
func (perm Permissions) CanUserAndGroupReadWrite() bool
func (Permissions) CanUserExecute ¶
func (perm Permissions) CanUserExecute() bool
func (Permissions) CanUserRead ¶
func (perm Permissions) CanUserRead() bool
func (Permissions) CanUserReadWrite ¶
func (perm Permissions) CanUserReadWrite() bool
func (Permissions) CanUserWrite ¶
func (perm Permissions) CanUserWrite() bool
func (Permissions) Executable ¶
func (perm Permissions) Executable() (user, group, others bool)
func (Permissions) FileMode ¶
func (perm Permissions) FileMode(isDir bool) os.FileMode
FileMode returns an os.FileMode for the given permissions together with the information if the file is a directory.
func (Permissions) Readable ¶
func (perm Permissions) Readable() (user, group, others bool)
func (Permissions) Writable ¶
func (perm Permissions) Writable() (user, group, others bool)
type PermissionsFileSystem ¶
type PermissionsFileSystem interface { FileSystem SetPermissions(filePath string, perm Permissions) error }
type ReadAllFileSystem ¶
type ReadCloser ¶
type ReadOnlyBase ¶
type ReadOnlyBase struct{}
ReadOnlyBase implements the writing methods of the FileSystem interface to do nothing and return ErrReadOnlyFileSystem. Intended to be used as base for read only file systems, so that only the read methods have to be implemented.
func (*ReadOnlyBase) MakeDir ¶
func (*ReadOnlyBase) MakeDir(dirPath string, perm []Permissions) error
func (*ReadOnlyBase) MatchAnyPattern ¶
func (*ReadOnlyBase) MatchAnyPattern(name string, patterns []string) (bool, error)
MatchAnyPattern returns true if name matches any of patterns, or if len(patterns) == 0. The match per pattern works like path.Match or filepath.Match
func (*ReadOnlyBase) OpenReadWriter ¶
func (*ReadOnlyBase) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)
func (*ReadOnlyBase) OpenWriter ¶
func (*ReadOnlyBase) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
func (*ReadOnlyBase) ReadableWritable ¶
func (*ReadOnlyBase) ReadableWritable() (readable, writable bool)
func (*ReadOnlyBase) Remove ¶
func (*ReadOnlyBase) Remove(filePath string) error
func (*ReadOnlyBase) SetPermissions ¶
func (*ReadOnlyBase) SetPermissions(filePath string, perm Permissions) error
type ReadSeekCloser ¶
ReadSeekCloser combines the interfaces io.Reader io.ReaderAt io.Seeker io.Closer
type ReadWriteSeekCloser ¶
type ReadWriteSeekCloser interface { io.Reader io.ReaderAt io.Writer io.WriterAt io.Seeker io.Closer }
ReadWriteSeekCloser combines the interfaces io.Reader io.ReaderAt io.Writer io.WriterAt io.Seeker io.Closer
type RenameFileSystem ¶
type RenameFileSystem interface { FileSystem // Rename only renames the file in its base directory // but does not move it into another directory. // If successful, this also changes the path of this File's implementation. Rename(filePath string, newName string) (newPath string, err error) }
RenameFileSystem can be implemented by file systems that have native file renaming functionality.
If a file system does not implement this interface then it's functionality will be emulated with other methods.
type SentinelError ¶
type SentinelError string
SentinelError is used for const sentinel errors
const ( // ErrReadOnlyFileSystem is returned when a file system doesn't support writes ErrReadOnlyFileSystem SentinelError = "file system is read-only" // ErrWriteOnlyFileSystem is returned when a file system doesn't support reads ErrWriteOnlyFileSystem SentinelError = "file system is write-only" // ErrInvalidFileSystem indicates an invalid file system ErrInvalidFileSystem SentinelError = "invalid file system" // ErrFileSystemClosed is returned after a file system Close method was called ErrFileSystemClosed SentinelError = "file system is closed" )
func (SentinelError) Error ¶
func (e SentinelError) Error() string
type StdDirEntry ¶
type StdDirEntry struct {
File File
}
StdDirEntry implements the io/fs.DirEntry interface from the standard library for a File.
func (StdDirEntry) Info ¶
func (de StdDirEntry) Info() (iofs.FileInfo, error)
Info returns the FileInfo for the file or subdirectory described by the entry. The returned FileInfo may be from the time of the original directory read or from the time of the call to Info. If the file has been removed or renamed since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist). If the entry denotes a symbolic link, Info reports the information about the link itself, not the link's target.
func (StdDirEntry) IsDir ¶
func (de StdDirEntry) IsDir() bool
IsDir reports whether the entry describes a directory.
func (StdDirEntry) Name ¶
func (de StdDirEntry) Name() string
Name returns the name of the file (or subdirectory) described by the entry. This name is only the final element of the path (the base name), not the entire path. For example, Name would return "hello.go" not "/home/gopher/hello.go".
func (StdDirEntry) Type ¶
func (de StdDirEntry) Type() iofs.FileMode
Type returns the type bits for the entry. The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.
type StdFS ¶
type StdFS struct {
File File
}
StdFS implements the io/fs.FS interface of the standard library for a File.
StdFS implements the following interfaces:
- io/fs.FS
- io/fs.SubFS
- io/fs.StatFS
- io/fs.GlobFS
- io/fs.ReadDirFS
- io/fs.ReadFileFS
func (StdFS) Glob ¶
Glob returns the names of all files matching pattern, providing an implementation of the top-level Glob function.
This method implements the io/fs.GlobFS interface.
func (StdFS) ReadDir ¶
ReadDir reads the named directory and returns a list of directory entries sorted by filename.
This method implements the io/fs.ReadDirFS interface.
func (StdFS) ReadFile ¶
ReadFile reads the named file and returns its contents.
This method implements the io/fs.ReadFileFS interface.
type TouchFileSystem ¶
type TouchFileSystem interface { FileSystem Touch(filePath string, perm []Permissions) error }
type TruncateFileSystem ¶
type TruncateFileSystem interface { FileSystem // Truncate resizes a file by not only // truncating to a smaller size but also // appending zeros to a bigger size // than the current one. Truncate(filePath string, size int64) error }
type UserFileSystem ¶
type VolumeNameFileSystem ¶
type VolumeNameFileSystem interface { FileSystem // VolumeName returns the name of the volume at the beginning of the filePath, // or an empty string if the filePath has no volume. // A volume is for example "C:" on Windows VolumeName(filePath string) string }
VolumeNameFileSystem should be implemented by file systems that have volume names.
type WatchFileSystem ¶
type WatchFileSystem interface { FileSystem // Watch a file or directory for changes. // If filePath describes a directory then // changes directly within it will be reported. // This does not apply changes in deeper // recursive sub-directories. // // It is valid to watch a file with multiple // callbacks, calling the returned cancel function // will cancel a particular watch. Watch(filePath string, onEvent func(File, Event)) (cancel func() error, err error) }
WatchFileSystem can be implemented by file systems that have file watching functionality.
type WriteAllFileSystem ¶
type WriteAllFileSystem interface { FileSystem WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error }
type WriteCloser ¶
type WriteCloser = io.WriteCloser
Source Files ¶
- compare.go
- contenthash.go
- copy.go
- errors.go
- event.go
- file.go
- fileinfo.go
- fileinfocache.go
- filereader.go
- filesystem.go
- fs.go
- invalidfilesystem.go
- listdir.go
- localfilesystem.go
- localfilesystem_unix.go
- logger.go
- memfile.go
- memfilesystem.go
- permissions.go
- readonlybase.go
- registry.go
- rwinterfaces.go
- servefilehttp.go
- sort.go
- specialpaths.go
- stddirentry.go
- stdfs.go
- subfilesystem.go
- utils.go
Directories ¶
Path | Synopsis |
---|---|
dropboxfs
module
|
|
fsimpl contains helper functions for implementing a fs.FileSystem
|
fsimpl contains helper functions for implementing a fs.FileSystem |
ftpfs
module
|
|
Package httpfs implements a read only file system for HTTP URLs.
|
Package httpfs implements a read only file system for HTTP URLs. |
s3fs
module
|
|
sftpfs
module
|
|
Package uuiddirs provides functions to split up a UUID into a series of sub-directories so that an unlimited number of UUIDs can be used as directories.
|
Package uuiddirs provides functions to split up a UUID into a series of sub-directories so that an unlimited number of UUIDs can be used as directories. |