wa-lang.org/wazero@v1.0.2/internal/testing/fs/fs.go (about) 1 package testfs 2 3 import "io/fs" 4 5 // compile-time check to ensure File implements fs.File 6 var _ fs.File = &File{} 7 8 // compile-time check to ensure FS implements fs.FS 9 var _ fs.FS = &FS{} 10 11 // FS emulates fs.FS. Note: the path (map key) cannot begin with "/"! 12 type FS map[string]*File 13 14 // Open implements the same method as documented on fs.FS. 15 func (f FS) Open(name string) (fs.File, error) { 16 if !fs.ValidPath(name) { 17 return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid} 18 } 19 if file, ok := f[name]; !ok { 20 return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist} 21 } else { 22 return file, nil 23 } 24 } 25 26 type File struct{ CloseErr error } 27 28 func (f *File) Close() error { return f.CloseErr } 29 func (f *File) Stat() (fs.FileInfo, error) { return nil, nil } 30 func (f *File) Read(_ []byte) (int, error) { return 0, nil } 31 func (f *File) Seek(_ int64, _ int) (int64, error) { return 0, nil }