package fs
import "codeberg.org/anaseto/goal/io/fs"
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
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.
func VFSubFS ¶
VFSubFS implements the subfs dyad.
fs subfs dir : return a derived file system value corresponding to the subtree rooted at dir.
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) Append ¶
Append appends the program representation of the value to dst.
func (*FS) Glob ¶
Glob implements fs.GlobFS.
func (*FS) Matches ¶
Matches reports whether fsys~y.
func (*FS) ReadDir ¶
ReadDir implements fs.ReadDirFS.
func (*FS) ReadFile ¶
ReadFile implements fs.ReadFileFS.
func (*FS) ReadFileOrDir ¶
ReadFileOrDir implements ReadFileOrDirFS.
func (*FS) Stat ¶
Stat implements fs.StatFS.
func (*FS) Sub ¶
Sub implements fs.SubFS.
func (*FS) Type ¶
Type returns type "/" for handle types.
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) Append ¶
Append appends a program representation of the value to dst.
func (*FileReader) Apply ¶
Apply implements goal.Callable for file reader handles.
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) File ¶
func (fr *FileReader) File() fs.File
File returns the underlying file.
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) Name ¶
func (fr *FileReader) Name() string
Name returns the file's name.
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.
func (*FileReader) WriteTo ¶
func (fr *FileReader) WriteTo(w io.Writer) (n int64, err error)
WriteTo implements the io.WriterTo inteface.
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.
Source Files ¶
file.go fs.go
- Version
- v1.1.0 (latest)
- Published
- Feb 17, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 28 minutes ago –
Tools for package owners.