Skip to content
go-libfossil Artifact [9eb28b17dd]
Login

Artifact [9eb28b17dd]

Artifact 9eb28b17dddd191c361cc55cc5f015f0584a4b1621eee12aa9fbe383cd61214c:


package simio

import (
	"io/fs"
	"os"
	"time"
)

// Storage abstracts filesystem operations for WASM portability.
type Storage interface {
	Stat(path string) (os.FileInfo, error)
	Remove(path string) error
	MkdirAll(path string, perm os.FileMode) error
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	ReadDir(path string) ([]fs.DirEntry, error)
	Chtimes(path string, atime, mtime time.Time) error
}

// OSStorage delegates to the os package. Used in production and WASI.
type OSStorage struct{}

func (OSStorage) Stat(path string) (os.FileInfo, error)                       { return os.Stat(path) }
func (OSStorage) Remove(path string) error                                     { return os.Remove(path) }
func (OSStorage) MkdirAll(path string, perm os.FileMode) error                { return os.MkdirAll(path, perm) }
func (OSStorage) ReadFile(path string) ([]byte, error)                         { return os.ReadFile(path) }
func (OSStorage) WriteFile(path string, data []byte, perm os.FileMode) error  { return os.WriteFile(path, data, perm) }
func (OSStorage) ReadDir(path string) ([]fs.DirEntry, error)                  { return os.ReadDir(path) }
func (OSStorage) Chtimes(path string, atime, mtime time.Time) error           { return os.Chtimes(path, atime, mtime) }