Skip to content

Commit 21beb15

Browse files
committed
Enable the iofs adapter to also return other interfaces from io/fs
Instead of relying on difficult casting, this improves developer experience by providing easy ways of convering a billy filesystem into the rest of the filesystem interfaces that are available in `io/fs`. This is a safe operation since we already ensure the type implements such interfaces some lines below my changes. Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent a6c6b50 commit 21beb15

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

helper/iofs/iofs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ func New(fs billyfs.Basic) fs.FS {
1616
return &adapterFs{fs: polyfill.New(fs)}
1717
}
1818

19+
// NewStatFS adapts a billy.Filesystem to a io.fs.StatFS.
20+
func NewStatFS(fs billyfs.Basic) fs.StatFS {
21+
return &adapterFs{fs: polyfill.New(fs)}
22+
}
23+
24+
// NewReadDirFS adapts a billy.Filesystem to a io.fs.ReadDirFS.
25+
func NewReadDirFS(fs billyfs.Basic) fs.ReadDirFS {
26+
return &adapterFs{fs: polyfill.New(fs)}
27+
}
28+
29+
// NewReadFileFS adapts a billy.Filesystem to a io.fs.ReadFileFS.
30+
func NewReadFileFS(fs billyfs.Basic) fs.ReadFileFS {
31+
return &adapterFs{fs: polyfill.New(fs)}
32+
}
33+
1934
type adapterFs struct {
2035
fs billyfs.Filesystem
2136
}

0 commit comments

Comments
 (0)