Skip to content

Commit

Permalink
Enable the iofs adapter to also return other interfaces from io/fs
Browse files Browse the repository at this point in the history
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 <ozz@stacklok.com>
  • Loading branch information
JAORMX committed Jan 10, 2025
1 parent a6c6b50 commit 21beb15
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions helper/iofs/iofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ func New(fs billyfs.Basic) fs.FS {
return &adapterFs{fs: polyfill.New(fs)}
}

// NewStatFS adapts a billy.Filesystem to a io.fs.StatFS.
func NewStatFS(fs billyfs.Basic) fs.StatFS {
return &adapterFs{fs: polyfill.New(fs)}
}

// NewReadDirFS adapts a billy.Filesystem to a io.fs.ReadDirFS.
func NewReadDirFS(fs billyfs.Basic) fs.ReadDirFS {
return &adapterFs{fs: polyfill.New(fs)}
}

// NewReadFileFS adapts a billy.Filesystem to a io.fs.ReadFileFS.
func NewReadFileFS(fs billyfs.Basic) fs.ReadFileFS {
return &adapterFs{fs: polyfill.New(fs)}
}

type adapterFs struct {
fs billyfs.Filesystem
}
Expand Down

0 comments on commit 21beb15

Please sign in to comment.