Documentation
¶
Overview ¶
Package fs provides functionality for working with read-only file system values and files in Goal.
Index ¶
- func DirEntries(des []fs.DirEntry) goal.V
- func Error(err error) string
- func NewFS(fsys fs.FS, progstr string) goal.V
- func NewFSError(err error) goal.V
- func NewFileReader(f fs.File, name string, buffered bool) goal.V
- func ReadFileOrDir(fsys fs.FS, name string) goal.V
- func VFSubFS(ctx *goal.Context, args []goal.V) goal.V
- type FS
- func (fsys *FS) Append(_ *goal.Context, dst []byte, _ bool) []byte
- func (fsys *FS) Glob(pattern string) ([]string, error)
- func (fsys *FS) Matches(y goal.BV) bool
- func (fsys *FS) ReadDir(name string) ([]fs.DirEntry, error)
- func (fsys *FS) ReadFile(name string) ([]byte, error)
- func (fsys *FS) ReadFileOrDir(name string) goal.V
- func (fsys *FS) Stat(name string) (fs.FileInfo, error)
- func (fsys *FS) Sub(dir string) (fs.FS, error)
- func (fsys *FS) Type() string
- type FileReader
- func (fr *FileReader) Append(ctx *goal.Context, dst []byte, _ bool) []byte
- func (fr *FileReader) Apply(_ *goal.Context, args []goal.V) goal.V
- func (fr *FileReader) Buffered() bool
- func (fr *FileReader) Close() error
- func (fr *FileReader) File() fs.File
- func (fr *FileReader) IsDir() bool
- func (fr *FileReader) Matches(y goal.BV) bool
- func (fr *FileReader) Name() string
- func (fr *FileReader) Read(p []byte) (n int, err error)
- func (fr *FileReader) ReadDir(n int) ([]fs.DirEntry, error)
- func (fr *FileReader) ReadString(delim byte) (string, error)
- func (fr *FileReader) Reader() *bufio.Reader
- func (fr *FileReader) Stat() (fs.FileInfo, error)
- func (fr *FileReader) Type() string
- func (fr *FileReader) WriteTo(w io.Writer) (n int64, err error)
- type ReadFileOrDirFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirEntries ¶
DirEntries translates a slice of fs.DirEntry values into a Goal dict value.
func Error ¶
Error returns an error string corresponding to one of the portable errors from fs package if possible, or calls Error() otherwise. It is used in the err field of returned error dict values.
func NewFS ¶
NewFS returns a new Goal file system value using fsys as underlying file system implementation and progstr as program string representation.
func NewFSError ¶
NewFSError converts a file-system Go error to a Goal error dict value with fields as described in the FAQ.
func NewFileReader ¶
NewFileReader returns a file reader handle for the given file. The name should usually be the name passed to Open. Buffering only works on non-dir files.
func ReadFileOrDir ¶
ReadFileOrDir reads the name file or directory and returns its contents as a Goal value, like `fs read name` would in Goal.
If fsys implements ReadFileOrDirFS, the code uses its specialized method.
Types ¶
type FS ¶
FS is a simple wrapper around an fs.FS file system interface value that also satisfies the goal.BV interface. It is used by subfs for file system values that do not implement fs.SubFS (unlike dirfs ones).
It may be used by extensions to easily create Goal file system values for types that do not require any extra methods.
FS transmits calls from the various optional file system methods of package fs to the underlying fs.FS value.
Use NewFS to create Goal file system values based on this type.
func (*FS) ReadFileOrDir ¶
ReadFileOrDir implements ReadFileOrDirFS.
type FileReader ¶
type FileReader struct {
// contains filtered or unexported fields
}
FileReader represents an fs.File implementing the goal.BV interface. It can make use of buffering for non-directory files.
Use NewFileReader to create Goal handle values based on this type.
func (*FileReader) Buffered ¶
func (fr *FileReader) Buffered() bool
Buffered reports whether the file reader is buffered.
func (*FileReader) Close ¶
func (fr *FileReader) Close() error
Close implements the fs.File interface.
func (*FileReader) IsDir ¶
func (fr *FileReader) IsDir() bool
IsDir reports whether the file is a directory.
func (*FileReader) Matches ¶
func (fr *FileReader) Matches(y goal.BV) bool
Matches reports whether fr~y.
func (*FileReader) Read ¶
func (fr *FileReader) Read(p []byte) (n int, err error)
Read implements the fs.File interface.
func (*FileReader) ReadDir ¶
func (fr *FileReader) ReadDir(n int) ([]fs.DirEntry, error)
ReadDir implements the fs.ReadDirFile interface.
func (*FileReader) ReadString ¶
func (fr *FileReader) ReadString(delim byte) (string, error)
ReadString reads until the first occurrence of delim in the input. This operation is only supported by buffered file handles.
func (*FileReader) Reader ¶
func (fr *FileReader) Reader() *bufio.Reader
Reader returns the underlying buffered reader, or nil if the file is unbuffered or a directory.
func (*FileReader) Stat ¶
func (fr *FileReader) Stat() (fs.FileInfo, error)
Stat implements the fs.File interface.
func (*FileReader) Type ¶
func (fr *FileReader) Type() string
Type returns type "h" for handle types.
type ReadFileOrDirFS ¶
type ReadFileOrDirFS interface {
fs.FS
// ReadFileOrDir reads the named file or directory and returns a Goal
// value with the results.
ReadFileOrDir(name string) goal.V
}
ReadFileOrDirFS is the interface implemented by a file system that provides an optimized implementation for reading a file or a directory in Goal using the read builtin.