embed: Begin refactor to use clearer paths
This commit is contained in:
parent
e75dc29de1
commit
e1ee569629
16 changed files with 431 additions and 181 deletions
31
internal/fsx/open.go
Normal file
31
internal/fsx/open.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package fsx
|
||||
|
||||
import "io/fs"
|
||||
|
||||
// OpenFS opens the named file in filesystem.
|
||||
// If opening the file results in an error, returns [ErrFile].
|
||||
func OpenFS(name string, fsys fs.FS) fs.File {
|
||||
file, err := fsys.Open(name)
|
||||
if err != nil {
|
||||
return ErrFile{Err: err}
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
||||
// ErrFile implements a no-op [fs.File].
|
||||
//
|
||||
// Every operation will return an underlying error
|
||||
type ErrFile struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (err ErrFile) Stat() (fs.FileInfo, error) {
|
||||
return nil, err.Err
|
||||
}
|
||||
func (err ErrFile) Read([]byte) (int, error) {
|
||||
return 0, err.Err
|
||||
}
|
||||
|
||||
func (err ErrFile) Close() error {
|
||||
return err.Err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue