Skip to content

Commit 40a2dbe

Browse files
committed
osfs: add Default to avoid repetitive code
1 parent 42ead41 commit 40a2dbe

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

osfs/os.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ const (
1818
defaultCreateMode = 0666
1919
)
2020

21+
// Default Filesystem representing the root of the os filesystem.
22+
var Default = &OS{}
23+
2124
// OS is a filesystem based on the os filesystem.
2225
type OS struct{}
2326

2427
// New returns a new OS filesystem.
2528
func New(baseDir string) billy.Filesystem {
26-
return chroot.New(&OS{}, baseDir)
29+
return chroot.New(Default, baseDir)
2730
}
2831

2932
func (fs *OS) Create(filename string) (billy.File, error) {

osfs/os_js.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import (
1111
// globalMemFs is the global memory fs
1212
var globalMemFs = memfs.New()
1313

14+
// Default Filesystem representing the root of in-memory filesystem for a
15+
// js/wasm environment.
16+
var Default = memfs.New()
17+
1418
// New returns a new OS filesystem.
1519
func New(baseDir string) billy.Filesystem {
16-
return chroot.New(globalMemFs, globalMemFs.Join("/", baseDir))
20+
return chroot.New(Default, Default.Join("/", baseDir))
1721
}

0 commit comments

Comments
 (0)