Documentation
¶
Index ¶
- Constants
- Variables
- func CleanDir(path string) errors.Error
- func Copy(src, dst string) errors.Error
- func CopyAll(src, dst string) errors.Error
- func CopyDir(src, dst string) errors.Error
- func CopyFile(src, dst string) errors.Error
- func CreateDirectory(path string) errors.Error
- func DeleteDirectory(path string, recursive bool) errors.Error
- func DeleteFile(path string) errors.Error
- func Exists(path string) (bool, errors.Error)
- func GetTempDir(prefix string) (string, errors.Error)
- func GetTempFile(pattern string) (string, errors.Error)
- func IsDir(path string) (bool, errors.Error)
- func IsFile(path string) (bool, errors.Error)
- func Move(src, dst string) errors.Error
- func MoveAll(src, dst string) errors.Error
- func MoveDir(src, dst string) errors.Error
- func MoveFile(src, dst string) errors.Error
- func ReadBytes(path string) ([]byte, errors.Error)
- func ReadLines(path string) ([]string, errors.Error)
- func ReadString(path string) (string, errors.Error)
- func Sort(files []FileInfo, cmp FileInfoComparer)
- func Walk(dir string, visitFileHandler VisitFileHandler, enterDirHandler EnterDirHandler, ...) errors.Error
- func WithTempDir(prefix string, f func(tmpDir string) errors.Error) errors.Error
- func WithTempFile(pattern string, f func(tmpFile string) errors.Error) errors.Error
- func WriteBytes(path string, content []byte) errors.Error
- func WriteLines(path string, lines []string) errors.Error
- func WriteString(path, content string) errors.Error
- type EnterDirHandler
- type File
- type FileInfo
- type FileInfoComparer
- type FileSystem
- func (fs *FileSystem) CanAll() bool
- func (fs *FileSystem) CanNavigate() bool
- func (fs *FileSystem) CanRead() bool
- func (fs *FileSystem) CanReadWrite() bool
- func (fs *FileSystem) CanTemp() bool
- func (fs *FileSystem) CanWrite() bool
- func (fs *FileSystem) CleanDir(dir string) errors.Error
- func (fs *FileSystem) Copy(src, dst string) errors.Error
- func (fs *FileSystem) CopyAll(src, dst string) errors.Error
- func (fs *FileSystem) CopyDir(src, dst string) errors.Error
- func (fs *FileSystem) CopyFile(src, dst string) errors.Error
- func (fs *FileSystem) CreateDirectory(path string) errors.Error
- func (fs *FileSystem) CreateFile(path string) (File, errors.Error)
- func (fs *FileSystem) DeleteDirectory(path string, recursive bool) errors.Error
- func (fs *FileSystem) DeleteFile(path string) errors.Error
- func (fs *FileSystem) Exists(path string) (bool, errors.Error)
- func (fs *FileSystem) GetTempDir(prefix string) (string, errors.Error)
- func (fs *FileSystem) GetTempFile(pattern string) (string, errors.Error)
- func (fs *FileSystem) IsDir(path string) (bool, errors.Error)
- func (fs *FileSystem) IsFile(path string) (bool, errors.Error)
- func (fs *FileSystem) Move(src, dst string) errors.Error
- func (fs *FileSystem) MoveAll(src, dst string) errors.Error
- func (fs *FileSystem) MoveDir(src, dst string) errors.Error
- func (fs *FileSystem) MoveFile(src, dst string) errors.Error
- func (fs *FileSystem) Open(path string) (File, errors.Error)
- func (fs *FileSystem) OpenFile(path string, flags OpenFlags) (File, errors.Error)
- func (fs *FileSystem) ReadBytes(path string) ([]byte, errors.Error)
- func (fs *FileSystem) ReadDir(path string) ([]FileInfo, errors.Error)
- func (fs *FileSystem) ReadLines(path string) ([]string, errors.Error)
- func (fs *FileSystem) ReadString(path string) (string, errors.Error)
- func (fs *FileSystem) Stat(path string) (FileInfo, errors.Error)
- func (fs *FileSystem) Walk(dir string, visitFileHandler VisitFileHandler, enterDirHandler EnterDirHandler, ...) errors.Error
- func (fs *FileSystem) WithTempDir(prefix string, f func(tmpDir string) errors.Error) errors.Error
- func (fs *FileSystem) WithTempFile(pattern string, f func(tmpFile string) errors.Error) errors.Error
- func (fs *FileSystem) WriteBytes(path string, content []byte) errors.Error
- func (fs *FileSystem) WriteLines(path string, lines []string) errors.Error
- func (fs *FileSystem) WriteString(path, content string) errors.Error
- type FileSystemDriver
- type LeaveDirHandler
- type LocalDriver
- func (d *LocalDriver) CreateDirectory(path string) errors.Error
- func (d *LocalDriver) DeleteDirectory(path string, recursive bool) errors.Error
- func (d *LocalDriver) DeleteFile(path string) errors.Error
- func (d *LocalDriver) Exists(path string) (bool, errors.Error)
- func (d *LocalDriver) GetTempDir(prefix string) (string, errors.Error)
- func (d *LocalDriver) GetTempFile(pattern string) (string, errors.Error)
- func (d *LocalDriver) IsDir(path string) (bool, errors.Error)
- func (d *LocalDriver) IsFile(path string) (bool, errors.Error)
- func (d *LocalDriver) MoveDir(src, dst string) errors.Error
- func (d *LocalDriver) MoveFile(src, dst string) errors.Error
- func (d *LocalDriver) OpenFile(path string, flags OpenFlags) (File, errors.Error)
- func (d *LocalDriver) ReadDir(path string) ([]FileInfo, errors.Error)
- func (d *LocalDriver) Stat(path string) (FileInfo, errors.Error)
- type NavigationFileSystemDriver
- type OpenFlags
- func (flag OpenFlags) Access() OpenFlags
- func (flag OpenFlags) Append() OpenFlags
- func (flag OpenFlags) Create() OpenFlags
- func (flag OpenFlags) Exclusive() OpenFlags
- func (flag OpenFlags) IsRead() bool
- func (flag OpenFlags) IsWrite() bool
- func (flag OpenFlags) Sync() OpenFlags
- func (flag OpenFlags) Truncate() OpenFlags
- type ReadFileSystemDriver
- type ReadWriteFileSystemDriver
- type TempFileSystemDriver
- type VisitFileHandler
- type WalkOptions
Constants ¶
const (
// DefaultLineDelimiter denotes the character or characther sequence to separate lines in text files.
DefaultLineDelimiter = "\n"
)
Variables ¶
var ( // Err is a generic file system related error. Err = errors.New("A file system error occured") // ErrNotSupported is returned when using a function that is not supported. ErrNotSupported = errors.New("Operation %s is not supported by the file system") // ErrNotExists occurs when an action failed becaus of a missing element of unknown type(file or directory). ErrNotExists = errors.New("The path %q does not exist") // ErrFileNotExists occurs when an action failed because of a missing file. ErrFileNotExists = errors.New("The file %q does not exist") // ErrDirectoryNotExists occurs when an action failed because of a missing directory. ErrDirectoryNotExists = errors.New("The directory %q does not exist") // ErrAccessDenied denotes an error caused by insufficient privileges. ErrAccessDenied = errors.New("Access to %q denied") // ErrNotEmpty occurs when trying to delete a non-empty directory without recursive flag. ErrNotEmpty = errors.New("The directory is not empty") )
var ( // OrderDefault sorts elements lexicographically ascending and moves directories to the top of the list. OrderDefault = func(f1, f2 FileInfo) int { if order := OrderDirectoriesFirst(f1, f2); order != 0 { return order } return OrderLexicographicAsc(f1, f2) } // OrderFilesFirst moves files to the top of the list. OrderFilesFirst = func(f1, f2 FileInfo) int { if !f1.IsDir() && f2.IsDir() { return -1 } else if f1.IsDir() && !f2.IsDir() { return 1 } return 0 } // OrderDirectoriesFirst moves directories to the top of the list. OrderDirectoriesFirst = func(f1, f2 FileInfo) int { return -OrderFilesFirst(f1, f2) } // OrderLexicographicAsc moves elements starting with A to the top of the list. OrderLexicographicAsc = func(f1, f2 FileInfo) int { if f1.Name() < f2.Name() { return -1 } else if f1.Name() > f2.Name() { return 1 } return 0 } // OrderLexicographicDesc moves elements starting with Z to the top of the list. OrderLexicographicDesc = func(f1, f2 FileInfo) int { return -OrderLexicographicAsc(f1, f2) } )
Functions ¶
func Copy ¶
Copy clone a file or directory to the target. If the target already exists, it must be the same element type (file or directory) to be overwritten.
func CreateDirectory ¶ added in v0.1.1
CreateDirectory creates a new directory and all parent directories if they do not exist.
func DeleteDirectory ¶ added in v0.1.0
DeleteDirectory deletes an empty directory. If recursive is set, all contained items will be deleted first.
func DeleteFile ¶ added in v0.1.0
DeleteFile deletes a file.
func GetTempDir ¶ added in v0.1.1
GetTempDir returns the path to an empty temporary dir.
func GetTempFile ¶ added in v0.1.1
GetTempFile returns the path to an empty temporary file.
func Move ¶ added in v0.2.0
Move moves a file or directory to a new location. If the target already exists, it must be the same element type (file or directory) to be overwritten.
func ReadLines ¶ added in v0.0.2
ReadLines returns all lines separated by "\n", "\r" or "\r\n" from a file.
func ReadString ¶ added in v0.1.0
ReadString returns the file content as string.
func Sort ¶ added in v0.2.1
func Sort(files []FileInfo, cmp FileInfoComparer)
Sort sorts an array of FileInfo objects using the given comparer.
func Walk ¶ added in v0.2.1
func Walk(dir string, visitFileHandler VisitFileHandler, enterDirHandler EnterDirHandler, leaveDirHandler LeaveDirHandler, options *WalkOptions) errors.Error
Walk calls the corresponding callback functions for ever file and directory contained in dir recursively.
The visit handler is called first for every file and directory that is found inside a directory. For directories, the enter dir handler is called subsequently. After this call, Walk instantly recurses into the given directory. Remaining files in the parent directory are visited after the corresponding leave callback. Leave callbacks are performed directly after the last element of a directory has been visited (and leaved in case of a sub-directory).
func WithTempDir ¶
WithTempDir creates a temporary directory and deletes it when f returns.
func WithTempFile ¶
WithTempFile creates a temporary file and deletes it when f returns.
func WriteBytes ¶ added in v0.1.0
WriteBytes writes all bytes to a file.
func WriteLines ¶ added in v0.0.3
WriteLines writes all lines separated by the default line separator to a file.
func WriteString ¶ added in v0.1.0
WriteString writes a string to a file.
Types ¶
type EnterDirHandler ¶ added in v0.2.0
type EnterDirHandler func(dir string, f FileInfo, isRoot bool, skipDir *bool) errors.Error // bool isRootDir
EnterDirHandler is called by Walk before a directory is entered. If skipDir is set to true, the directory will not be visited.
type File ¶ added in v0.0.2
File is the instance object for an opened file.
func CreateFile ¶ added in v0.1.0
CreateFile a new file (or truncate an existing) and return the file instance handle.
type FileInfo ¶ added in v0.0.2
FileInfo contains meta information for a file.
type FileInfoComparer ¶ added in v0.2.1
FileInfoComparer returns true, when f1 should be displayed before f2.
func NewCompoundComparer ¶ added in v0.2.1
func NewCompoundComparer(compareFuncs ...FileInfoComparer) FileInfoComparer
NewCompoundComparer returns a new comparer based on the prioritized list of compare functions. The first comparer has the highest priority.
type FileSystem ¶
type FileSystem struct {
LineSeparator string
// contains filtered or unexported fields
}
FileSystem offers advanced functionality based on a file system driver.
var ( // DefaultFileSystem denots the file system used for all default accessors. DefaultFileSystem *FileSystem )
func New ¶ added in v0.0.2
func New() *FileSystem
New returns a new file system with local file system driver.
func NewWithDriver ¶ added in v0.1.0
func NewWithDriver(driver interface{}) *FileSystem
NewWithDriver returns a new file system using the given file system driver. The given driver must implement at least one of the file system driver interfaces.
func (*FileSystem) CanAll ¶ added in v0.1.0
func (fs *FileSystem) CanAll() bool
CanAll returns true when the file system offers complete functionality.
func (*FileSystem) CanNavigate ¶ added in v0.2.0
func (fs *FileSystem) CanNavigate() bool
CanNavigate returns true when the file system allows to list files and directories.
func (*FileSystem) CanRead ¶ added in v0.1.0
func (fs *FileSystem) CanRead() bool
CanRead returns true when the file system can perform read operations.
func (*FileSystem) CanReadWrite ¶ added in v0.1.0
func (fs *FileSystem) CanReadWrite() bool
CanReadWrite returns true when the file system can perform both read and write operations.
func (*FileSystem) CanTemp ¶ added in v0.1.0
func (fs *FileSystem) CanTemp() bool
CanTemp returns true when the file system can create temporary files and directories.
func (*FileSystem) CanWrite ¶ added in v0.1.0
func (fs *FileSystem) CanWrite() bool
CanWrite returns true when the file system can perform write operations.
func (*FileSystem) CleanDir ¶ added in v0.1.0
func (fs *FileSystem) CleanDir(dir string) errors.Error
CleanDir removes all files and directories from a directory.
func (*FileSystem) Copy ¶ added in v0.1.1
func (fs *FileSystem) Copy(src, dst string) errors.Error
Copy clone a file or directory to the target. If the target already exists, it must be the same element type (file or directory) to be overwritten.
func (*FileSystem) CopyAll ¶ added in v0.1.1
func (fs *FileSystem) CopyAll(src, dst string) errors.Error
CopyAll copies all files and directories contained in src to dst.
func (*FileSystem) CopyDir ¶ added in v0.1.1
func (fs *FileSystem) CopyDir(src, dst string) errors.Error
CopyDir recursively clones a directory overwriting all existing files.
func (*FileSystem) CopyFile ¶ added in v0.1.0
func (fs *FileSystem) CopyFile(src, dst string) errors.Error
CopyFile clones a file and overwrites the existing one.
func (*FileSystem) CreateDirectory ¶ added in v0.1.1
func (fs *FileSystem) CreateDirectory(path string) errors.Error
CreateDirectory creates a new directory and all parent directories if they do not exist.
func (*FileSystem) CreateFile ¶ added in v0.1.0
func (fs *FileSystem) CreateFile(path string) (File, errors.Error)
CreateFile a new file (or truncate an existing) and return the file instance handle.
func (*FileSystem) DeleteDirectory ¶ added in v0.1.0
func (fs *FileSystem) DeleteDirectory(path string, recursive bool) errors.Error
DeleteDirectory deletes an empty directory. If recursive is set, all contained items will be deleted first.
func (*FileSystem) DeleteFile ¶ added in v0.1.0
func (fs *FileSystem) DeleteFile(path string) errors.Error
DeleteFile deletes a file.
func (*FileSystem) Exists ¶ added in v0.1.0
func (fs *FileSystem) Exists(path string) (bool, errors.Error)
Exists returns true, if the given path is a file or directory.
func (*FileSystem) GetTempDir ¶ added in v0.1.1
func (fs *FileSystem) GetTempDir(prefix string) (string, errors.Error)
GetTempDir returns the path to an empty temporary dir.
func (*FileSystem) GetTempFile ¶ added in v0.1.1
func (fs *FileSystem) GetTempFile(pattern string) (string, errors.Error)
GetTempFile returns the path to an empty temporary file.
func (*FileSystem) IsDir ¶ added in v0.1.0
func (fs *FileSystem) IsDir(path string) (bool, errors.Error)
IsDir returns true, if the given path is a directory.
func (*FileSystem) IsFile ¶ added in v0.1.0
func (fs *FileSystem) IsFile(path string) (bool, errors.Error)
IsFile returns true, if the given path is a file.
func (*FileSystem) Move ¶ added in v0.2.0
func (fs *FileSystem) Move(src, dst string) errors.Error
Move moves a file or directory to a new location. If the target already exists, it must be the same element type (file or directory) to be overwritten.
func (*FileSystem) MoveAll ¶ added in v0.1.1
func (fs *FileSystem) MoveAll(src, dst string) errors.Error
MoveAll moves all files and directories contained in src to dst.
func (*FileSystem) MoveDir ¶ added in v0.1.0
func (fs *FileSystem) MoveDir(src, dst string) errors.Error
MoveDir moves a directory to a new location.
func (*FileSystem) MoveFile ¶ added in v0.1.0
func (fs *FileSystem) MoveFile(src, dst string) errors.Error
MoveFile moves a file to a new location.
func (*FileSystem) Open ¶ added in v0.1.0
func (fs *FileSystem) Open(path string) (File, errors.Error)
Open opens a file instance for reading and returns the handle.
func (*FileSystem) OpenFile ¶ added in v0.1.0
OpenFile opens a general purpose file instance based on flags and returns the handle.
func (*FileSystem) ReadBytes ¶ added in v0.1.0
func (fs *FileSystem) ReadBytes(path string) ([]byte, errors.Error)
ReadBytes returns all bytes contained in a file.
func (*FileSystem) ReadDir ¶ added in v0.1.0
func (fs *FileSystem) ReadDir(path string) ([]FileInfo, errors.Error)
ReadDir returns all files and directories contained in a directory.
func (*FileSystem) ReadLines ¶ added in v0.1.0
func (fs *FileSystem) ReadLines(path string) ([]string, errors.Error)
ReadLines returns all files contained in a text file.
func (*FileSystem) ReadString ¶ added in v0.1.0
func (fs *FileSystem) ReadString(path string) (string, errors.Error)
ReadString returns the file content as string.
func (*FileSystem) Stat ¶ added in v0.2.1
func (fs *FileSystem) Stat(path string) (FileInfo, errors.Error)
Stat returns file or directory stats for a given path.
func (*FileSystem) Walk ¶ added in v0.2.0
func (fs *FileSystem) Walk(dir string, visitFileHandler VisitFileHandler, enterDirHandler EnterDirHandler, leaveDirHandler LeaveDirHandler, options *WalkOptions) errors.Error
Walk calls the corresponding callback functions for ever file and directory contained in dir recursively.
The visit handler is called first for every file and directory that is found inside a directory. For directories, the enter dir handler is called subsequently. After this call, Walk instantly recurses into the given directory. Remaining files in the parent directory are visited after the corresponding leave callback. Leave callbacks are performed directly after the last element of a directory has been visited (and leaved in case of a sub-directory).
func (*FileSystem) WithTempDir ¶ added in v0.1.0
WithTempDir creates a temporary directory and deletes it when f returns.
func (*FileSystem) WithTempFile ¶ added in v0.1.0
func (fs *FileSystem) WithTempFile(pattern string, f func(tmpFile string) errors.Error) errors.Error
WithTempFile creates a temporary file and deletes it when f returns.
func (*FileSystem) WriteBytes ¶ added in v0.1.0
func (fs *FileSystem) WriteBytes(path string, content []byte) errors.Error
WriteBytes writes all bytes to a file.
func (*FileSystem) WriteLines ¶ added in v0.1.0
func (fs *FileSystem) WriteLines(path string, lines []string) errors.Error
WriteLines writes all lines to a file using the default line delimiter.
func (*FileSystem) WriteString ¶ added in v0.1.0
func (fs *FileSystem) WriteString(path, content string) errors.Error
WriteString writes a string to a file.
type FileSystemDriver ¶ added in v0.0.2
type FileSystemDriver interface {
TempFileSystemDriver
}
FileSystemDriver describes a complete file system function set.
type LeaveDirHandler ¶ added in v0.2.0
LeaveDirHandler is called by Walk after all elements inside a directory have been processed.
type LocalDriver ¶ added in v0.0.2
type LocalDriver struct {
Root string
}
LocalDriver allows access to the file system of the host machine.
func (*LocalDriver) CreateDirectory ¶ added in v0.1.0
func (d *LocalDriver) CreateDirectory(path string) errors.Error
CreateDirectory creates a new directory and all parent directories if they do not exist.
func (*LocalDriver) DeleteDirectory ¶ added in v0.1.0
func (d *LocalDriver) DeleteDirectory(path string, recursive bool) errors.Error
DeleteDirectory deletes an empty directory. Set recursive to true to also remove directory content.
func (*LocalDriver) DeleteFile ¶ added in v0.1.0
func (d *LocalDriver) DeleteFile(path string) errors.Error
DeleteFile deletes a file.
func (*LocalDriver) Exists ¶ added in v0.0.2
func (d *LocalDriver) Exists(path string) (bool, errors.Error)
Exists returns true, if the given path is a file or directory.
func (*LocalDriver) GetTempDir ¶ added in v0.1.0
func (d *LocalDriver) GetTempDir(prefix string) (string, errors.Error)
GetTempDir returns the path to an empty temporary dir.
func (*LocalDriver) GetTempFile ¶ added in v0.0.2
func (d *LocalDriver) GetTempFile(pattern string) (string, errors.Error)
GetTempFile returns the path to an empty temporary file.
func (*LocalDriver) IsDir ¶ added in v0.0.2
func (d *LocalDriver) IsDir(path string) (bool, errors.Error)
IsDir returns true, if the given path is a directory.
func (*LocalDriver) IsFile ¶ added in v0.0.2
func (d *LocalDriver) IsFile(path string) (bool, errors.Error)
IsFile returns true, if the given path is a file.
func (*LocalDriver) MoveDir ¶ added in v0.1.0
func (d *LocalDriver) MoveDir(src, dst string) errors.Error
MoveDir moves a directory to a new location.
func (*LocalDriver) MoveFile ¶ added in v0.1.0
func (d *LocalDriver) MoveFile(src, dst string) errors.Error
MoveFile moves a file to a new location.
func (*LocalDriver) OpenFile ¶ added in v0.1.0
OpenFile opens a file instance and returns the handle.
type NavigationFileSystemDriver ¶ added in v0.2.0
type NavigationFileSystemDriver interface {
}
NavigationFileSystemDriver describes functionality to list files and directories but does not allow access to file content.
type OpenFlags ¶ added in v0.1.0
type OpenFlags int
OpenFlags specifies information on how to open a file.
const ( // OpenReadOnly denotes opening a file using read-only access. OpenReadOnly OpenFlags = OpenFlags(os.O_RDONLY) // OpenWriteOnly denotes opening a file using write-only access. OpenWriteOnly OpenFlags = OpenFlags(os.O_WRONLY) // OpenReadWrite denotes opening a file using read-write access. OpenReadWrite OpenFlags = OpenFlags(os.O_RDWR) )
func (OpenFlags) IsRead ¶ added in v0.1.0
IsRead returns whether the given flags require read access.
func (OpenFlags) IsWrite ¶ added in v0.1.0
IsWrite returns whether the given flags require write access.
type ReadFileSystemDriver ¶ added in v0.0.2
type ReadFileSystemDriver interface {
NavigationFileSystemDriver
OpenFile(path string, flags OpenFlags) (File, errors.Error)
}
ReadFileSystemDriver describes functionality to read from a file system.
type ReadWriteFileSystemDriver ¶ added in v0.0.2
type ReadWriteFileSystemDriver interface {
ReadFileSystemDriver
CreateDirectory(path string) errors.Error
DeleteFile(path string) errors.Error
DeleteDirectory(path string, recursive bool) errors.Error
MoveFile(src, dst string) errors.Error
MoveDir(src, dst string) errors.Error
}
ReadWriteFileSystemDriver describes functionality to write to a file system.
type TempFileSystemDriver ¶ added in v0.0.2
type TempFileSystemDriver interface {
ReadWriteFileSystemDriver
GetTempFile(pattern string) (string, errors.Error)
GetTempDir(prefix string) (string, errors.Error)
}
TempFileSystemDriver describes functionality to create temporary files and directories on a file system.
type VisitFileHandler ¶ added in v0.2.0
VisitFileHandler is called by Walk for every file and directory that is found recursively.
type WalkOptions ¶ added in v0.2.0
type WalkOptions struct {
// SkipSubDirs denotes whether the directory is traversed recursively or not.
SkipSubDirs bool
// VisitRootDir causes Walk to also call the visit handler for the walked directory itself.
VisitRootDir bool
// EnterLeaveCallbacksForRoot denotes whether the enter and leave callbacks are called for the walked directory itself.
EnterLeaveCallbacksForRoot bool
// VisitOrder denotes a function that is used to sort the sequence of files inside a single directory to specify in which order the sub-elements are processed.
VisitOrder FileInfoComparer
}
WalkOptions can be used to specify the behavior of Walk like visit order and search strategy.