Skip to content

Commit

Permalink
osfs: add Default to avoid repetitive code
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Apr 28, 2021
1 parent 42ead41 commit 40a2dbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion osfs/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ const (
defaultCreateMode = 0666
)

// Default Filesystem representing the root of the os filesystem.
var Default = &OS{}

// OS is a filesystem based on the os filesystem.
type OS struct{}

// New returns a new OS filesystem.
func New(baseDir string) billy.Filesystem {
return chroot.New(&OS{}, baseDir)
return chroot.New(Default, baseDir)
}

func (fs *OS) Create(filename string) (billy.File, error) {
Expand Down
6 changes: 5 additions & 1 deletion osfs/os_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (
// globalMemFs is the global memory fs
var globalMemFs = memfs.New()

// Default Filesystem representing the root of in-memory filesystem for a
// js/wasm environment.
var Default = memfs.New()

// New returns a new OS filesystem.
func New(baseDir string) billy.Filesystem {
return chroot.New(globalMemFs, globalMemFs.Join("/", baseDir))
return chroot.New(Default, Default.Join("/", baseDir))
}

0 comments on commit 40a2dbe

Please sign in to comment.