Documentation
¶
Index ¶
- Variables
- func Base(fsys ReadOnly) path.Absolute
- func Checksum(data io.Reader) (checksum string, err error)
- func ClearDir(fsys FS, dir path.Relative) error
- func CopyDir(srcfs FS, srcDir path.Relative, trgtfs FS, trgtDir path.Relative) error
- func CopyFile(srcfs FS, srcFile path.Relative, trgtfs FS, trgtFile path.Relative) error
- func CopyFileWithCheck(srcfs FS, srcFile path.Relative, trgtfs FS, trgtFile path.Relative, ...) error
- func CreateFile(fs ExtWriteable, f path.Relative, bt []byte) error
- func CreateFileFrom(fs ExtWriteable, f path.Relative, rd io.Reader) error
- func DirSize(fsys ReadOnly, dir path.Relative) (size int64)
- func Drive(loc path.Local) (string, error)
- func FreeSpace(drive string, freeBytesAvailable *uint64) error
- func IsEmpty(fsys ReadOnly, dir path.Relative) bool
- func MkDir(fs ExtWriteable, rel path.Relative) error
- func MkDirAll(fs ExtWriteable, rel path.Relative) error
- func MoveDir(srcfs FS, srcDir path.Relative, trgtfs FS, trgDir path.Relative) error
- func MoveFile(srcfs FS, srcFile path.Relative, trgtfs FS, trgDir path.Relative) error
- func OnUnix() bool
- func OnWindows() bool
- func ReadCloser(rd io.Reader) io.ReadCloser
- func ReadDirNames(fs ReadOnly, dir path.Relative) ([]string, error)
- func ReadDirPaths(fs ReadOnly, dir path.Relative) ([]path.Relative, error)
- func ReadFile(fs ReadOnly, f path.Relative) ([]byte, error)
- func WriteFile(fs ExtWriteable, f path.Relative, bt []byte, recursive bool) error
- func WriteFileFrom(fs ExtWriteable, f path.Relative, rd io.Reader, recursive bool) error
- type ExtClose
- type ExtDeleteable
- type ExtGlob
- type ExtLock
- type ExtMeta
- type ExtModeable
- type ExtMoveable
- type ExtReadSeekable
- type ExtRenameable
- type ExtSpaceReporter
- type ExtURL
- type ExtWriteSeekable
- type ExtWriteable
- type FS
- type FileMode
- type Local
- type ReadOnly
- type ReadSeekCloser
- type Remote
- type TestFS
- type WalkFunc
- type WriteSeekCloser
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotSupported = errors.Error("%s not supported by %T") ErrNotFound = errors.Error("%s not found") ErrNotEmpty = errors.Error("%s not empty") ErrAlreadyExists = errors.Error("%s already exists") ErrWhileReading = errors.Error("could not read %s: %w") ErrExpectedFile = errors.Error("%s is not a file") ErrExpectedDir = errors.Error("%s is not a directory") ErrExpectedAbsPath = errors.Error("%s is no absolute path") ErrExpectedWinDrive = errors.Error("%s is no windows drive letter") ErrWhileChecksumming = errors.Error("could not make checksum for file %s: %w") ErrChecksumNotMatch = errors.Error("checksums did not match %v vs %v") )
var SkipAll = iofs.SkipAll
var SkipDir = iofs.SkipDir
Functions ¶
func Checksum ¶
see https://stackoverflow.com/questions/60328216/how-to-calculate-sha256-of-a-very-large-file-in-go
func CopyFile ¶
TODO implement TODO: first check, if there is enough space left CopyFile copies the given file of the given FS to the given target in the given target fs. srcfs and trgtfs may be the same. In that case, and if FS also implements the Mover interface and if srcFile and trgtFile are on the same Mountpoint the more efficient Mover.Move method is used
func CopyFileWithCheck ¶
func CopyFileWithCheck(srcfs FS, srcFile path.Relative, trgtfs FS, trgtFile path.Relative, checksumFN func(io.Reader) (string, error)) error
CopyFileWithCheck is like CopyFile but doing another read to verify, that the checksum of both the src and target file matches. if the checksum does not match, the targetfile is removed
func CreateFile ¶ added in v0.6.0
func CreateFile(fs ExtWriteable, f path.Relative, bt []byte) error
CreateFile does return an error, if the file already exists or if the parent directory does not exist
func CreateFileFrom ¶ added in v0.6.0
CreateFileFrom does return an error, if the file already exists or if the parent directory does not exist
func DirSize ¶
DirSize returns the size of the given directory. If the given path is not a directory or any error occurs, -1 is returned. If the given dir is empty, 0 is returned. TODO test
func FreeSpace ¶ added in v0.17.0
see https://stackoverflow.com/questions/20108520/get-amount-of-free-disk-space-using-go
func IsEmpty ¶
IsEmpty returns, if the given dir is empty or does not exist or is not a directory, but a file.
func MoveFile ¶
MoveFile moves a file. If source and target filesystems are the same, the mountpoints of the source and target paths are the same and the filesystem is supporting the Moveable interface, the optimized Move method of the filesystem is used. Otherwise a copy of the file is made and the source file is only deleted, if the copying process was successfull. TODO check
func ReadCloser ¶
func ReadCloser(rd io.Reader) io.ReadCloser
func ReadDirNames ¶ added in v0.5.0
ReadDirNames returns the names of the dirs and files in a directory and returns them
func ReadDirPaths ¶ added in v0.5.0
ReadDirPaths returns the full paths (including dir) of the files and folders inside dir
func WriteFileFrom ¶ added in v0.6.0
Types ¶
type ExtDeleteable ¶
type ExtDeleteable interface { ReadOnly // Delete deletes either a file or a folder. // The deletion of folders may not be supported. In this case an error has to be returned, if the given path // is a folder. // If recursive is set to true, directories will be deleted, even if they are not empty. // If the given path does not exist, no error is returned. // If the given path can't be deleted, either because it is not empty and recursive was not set, or // because of missing permissions, an error is returned. Delete(p path.Relative, recursive bool) error }
ExtDeleteable is an extension interface for a filesystem that adds the ability to delete files and folders. The deletion of folders may not be supported. In this case an error has to be returned, if the given path is a folder.
type ExtMeta ¶
type ExtMeta interface { ReadOnly WriteWithMeta(p path.Relative, data io.ReadCloser, meta map[string][]byte, recursive bool) error SetMeta(p path.Relative, meta map[string][]byte) error GetMeta(p path.Relative) (map[string][]byte, error) }
ExtMeta is an interface for a filesystem, that adds ability to set and get meta data
type ExtModeable ¶
type ExtModeable interface { ReadOnly // WriteWithMode behaves like Writeable.Write and only differs that the given filemod is used within the creation // (instead of the default filemods). WriteWithMode(p path.Relative, data io.ReadCloser, mode FileMode, recursive bool) error // GetMode returns the FileMode of the given path, or an error if the path does not exist. GetMode(p path.Relative) (FileMode, error) // SetMode set the given FileMode for the given path. If the path does not exist, an error is returned. SetMode(p path.Relative, m FileMode) error }
ExtModeable is an interface for a filesystem, that adds the ability to read and set FileMode (permissions) for files and folders. To allow the creation of files with restricted permissions, this interface includes a method to write with a given mode, which is not supported by the FS interface. ExtModeable should be implemented mainly by local filesystems.
type ExtMoveable ¶
type ExtMoveable interface { ReadOnly // Drive returns the drive (drive letter or UNC on windows, mountpoint of unix) of the given relative path // for moving between mountpoints or filesystem, just copy all files via CopyFile or CopyDir and // remove afterwards (better to check the copy by comparing checksums or the original and the new file) Drive(p path.Relative) (path.Local, error) // Move should return an error, if // - the src does not exist // - src is a directory and moving of directories is not supported by the fs // - the resulting path trgDir.Join(path.Name(src)) does already exist // - src and trgdir have different mountpoints Move(src path.Relative, trgDir path.Relative) error }
ExtMoveable is an interface for a filesystem, that adds the native / optimized (e.g. zero copy) ability to move files and folders.
type ExtReadSeekable ¶ added in v0.21.0
type ExtReadSeekable interface { ReadOnly // ReadSeeker returns an io.ReadSeekCloser for the content of a file. // The io.ReadSeekCloser should be closed after reading all. // An error is only returned, if p is a directory or if p does not exist. ReadSeeker(p path.Relative) (ReadSeekCloser, error) }
ExtReadSeekable is an extention interface for a filesystem that adds the ability to seek in files.
type ExtRenameable ¶
type ExtRenameable interface { ReadOnly // Rename deletes either a file or a folder. // The given name must not be a path, so it must not contain path seperators. // If the given path does not exist, an error is returned. // If the renaming procedure was not successfull, an error is returned. // Please note that Rename behaves differently from the traditional unix operation with the same name. // Rename can't be used to move a file or folder to a different folder, but only to change the name of the // file or folder while staying in the same folder. // To move files, you need the Move function which would be more efficient, if the filesystem // supports the Moveable interface. Rename(p path.Relative, name string) error }
ExtRenameable is an interface for a filesystem, that adds the ability to rename files and folders. The renaming of folders may not be supported. In this case an error has to be returned, if the given path is a folder.
type ExtSpaceReporter ¶
type ExtURL ¶
type ExtURL interface { ReadOnly HostName() string Port() int UserName() string Password() string Scheme() string }
ExtURL is an interface for a filesystem, that adds the ability to get url based information
type ExtWriteSeekable ¶ added in v0.21.0
type ExtWriteSeekable interface { ExtWriteable // WriteSeeker returns a WriteSeekCloser where Write and Seek can be called. Close must be called when the writing is finished WriteSeeker(p path.Relative) (WriteSeekCloser, error) }
ExtWriteSeekable is an extention interface for a filesystem that adds the ability to seek in files.
type ExtWriteable ¶
type ExtWriteable interface { ReadOnly // Write writes either a file or a folder to the given path with default permissions. // If p is a directory, data is ignored. // If recursive is set to true, all intermediate directories will be created if necessary. // Write always overwrites an existing file. If you need to make sure that a file at the given // path should not be overwritten, check with Exists(p) first. // If p is a directory that already exists, nothing will be done and no error will be returned. Write(p path.Relative, data io.ReadCloser, recursive bool) error }
ExtWriteable is an extention interface for a filesystem that adds the ability to write files and folders.
type FS ¶
type FS interface { ReadOnly ExtWriteable ExtDeleteable }
FS is an interface for a complete filesystem, that covers the ability to read, write, delete and rename files and folders.
type Local ¶
type Local interface { FS ExtReadSeekable ExtWriteSeekable ExtMoveable ExtModeable ExtRenameable ExtSpaceReporter ExtGlob }
Local is the interface for a local filesystem
type ReadOnly ¶
type ReadOnly interface { // Reader returns an io.ReadCloser that reads in the whole file or in case of a directory // the relative paths related to the directory path, separated by a unix linefeed (\n). // The io.ReadCloser should be closed after reading all. // An error is only returned, if p does not exist or in case of directories, if reading of directories is not supported. Reader(p path.Relative) (io.ReadCloser, error) // Exists does return, if a file or directory with the given path exists. Exists(p path.Relative) bool // ModTime return the time of the last modification of p. // It returns an error, if p does not exist. ModTime(p path.Relative) (time.Time, error) // wenn nicht unterstützt: immer fehler zurückgeben // Abs converts the given relative path to an absolute path, based on the base of the filesystem. Abs(p path.Relative) path.Absolute // Size returns the size of the given p in bytes // If the given p does not exist or the size could not be determined, -1 is returned. // The size of a folder is always 0. In order to calculate the real size of a folder, // use DirSize() Size(p path.Relative) int64 // int64 is large enough for any filesystem }
ReadOnly is a minimal readonly interface for a filesystem. Any "io/fs.FS" can be converted to the ReadOnly interface by calling wrapfs.New()
type ReadSeekCloser ¶ added in v0.11.0
type ReadSeekCloser interface { io.Reader //in contrast to io.Seeker, here Seek always Seeks from the beginning of the file (whence=0) // other behaviors can be simply implemented by tracking (whence=1, starting from last position) // or via calculation by file size( whence=2, from the end of the file) Seek(offset int64) error io.Closer }
func NewReadSeekCloser ¶ added in v0.21.0
func NewReadSeekCloser(rd io.ReadSeeker) ReadSeekCloser
type TestFS ¶
TestFS is an interface that is only interesting for testing. It includes all interfaces and extension.
type WriteSeekCloser ¶ added in v0.21.0
type WriteSeekCloser interface { io.Writer //in contrast to io.Seeker, here Seek always Seeks from the beginning of the file (whence=0) // other behaviors can be simply implemented by tracking (whence=1, starting from last position) // or via calculation by file size( whence=2, from the end of the file) Seek(offset int64) error // when writing is finished Close must be called io.Closer }