Documentation ¶
Overview ¶
Package jsfs provides a Node.js style filesystem API in Go that can be used to allow os functions to work on wasm.
Index ¶
- Variables
- func BlockCount(size, blockSize int64) int64
- func ErrBadFile(identifier string) error
- func ErrBadFileNumber(fd uint64) error
- func FuncOf[F Func](name string, fn F) js.Func
- func GetErrType(err error, debugMessage string) string
- func JSBoolFunc(b bool) js.Func
- func JSError(err error, message string, args ...js.Value) js.Value
- func JSMode(mode os.FileMode) uint32
- func JSStat(info os.FileInfo) js.Value
- func NewNullFile(name string) hackpadfs.File
- func NormPath(p string) string
- func SetFunc[F Func](v js.Value, name string, fn F)
- func WrapError(err error, code string) error
- type BufferedLogger
- func (b *BufferedLogger) Close() error
- func (b *BufferedLogger) Flush()
- func (b *BufferedLogger) Name() string
- func (b *BufferedLogger) Print(s string) int
- func (b *BufferedLogger) Read(p []byte) (n int, err error)
- func (b *BufferedLogger) Stat() (os.FileInfo, error)
- func (b *BufferedLogger) Write(p []byte) (n int, err error)
- type FS
- func (f *FS) Chmod(args []js.Value) (any, error)
- func (f *FS) Chown(args []js.Value) (any, error)
- func (f *FS) Close(args []js.Value) (any, error)
- func (f *FS) ConfigUnix() error
- func (f *FS) Fchmod(args []js.Value) (any, error)
- func (f *FS) Fchown(args []js.Value) (any, error)
- func (f *FS) Fstat(args []js.Value) (any, error)
- func (f *FS) Fsync(args []js.Value) (any, error)
- func (f *FS) Ftruncate(args []js.Value) (any, error)
- func (f *FS) GetFile(args []js.Value) (hackpadfs.File, error)
- func (f *FS) Lchown(args []js.Value) (any, error)
- func (f *FS) Link(args []js.Value) (any, error)
- func (f *FS) Lstat(args []js.Value) (any, error)
- func (f *FS) Mkdir(args []js.Value) (any, error)
- func (f *FS) MkdirAll(args []js.Value) (any, error)
- func (f *FS) NewFile(absPath string, flags int, mode os.FileMode) (hackpadfs.File, error)
- func (f *FS) Open(args []js.Value) (any, error)
- func (f *FS) OpenImpl(path string, flags int, mode hackpadfs.FileMode) (uint64, error)
- func (f *FS) Read(args []js.Value) (any, any, error)
- func (f *FS) ReadFile(args []js.Value) (any, error)
- func (f *FS) Readdir(args []js.Value) (any, error)
- func (f *FS) Readlink(args []js.Value) (any, error)
- func (f *FS) Rename(args []js.Value) (any, error)
- func (f *FS) Rmdir(args []js.Value) (any, error)
- func (f *FS) Stat(args []js.Value) (any, error)
- func (f *FS) Symlink(args []js.Value) (any, error)
- func (f *FS) Truncate(args []js.Value) (any, error)
- func (f *FS) Unlink(args []js.Value) (any, error)
- func (f *FS) Utimes(args []js.Value) (any, error)
- func (f *FS) Write(args []js.Value) (any, any, error)
- type Func
- type NullFile
- func (f NullFile) Close() error
- func (f NullFile) Read(p []byte) (n int, err error)
- func (f NullFile) ReadAt(p []byte, off int64) (n int, err error)
- func (f NullFile) Seek(offset int64, whence int) (int64, error)
- func (f NullFile) Stat() (os.FileInfo, error)
- func (f NullFile) Truncate(size int64) error
- func (f NullFile) Write(p []byte) (n int, err error)
- func (f NullFile) WriteAt(p []byte, off int64) (n int, err error)
- type NullStat
Constants ¶
This section is empty.
Variables ¶
var ( FuncTrue = js.FuncOf(func(this js.Value, args []js.Value) interface{} { return true }) FuncFalse = js.FuncOf(func(this js.Value, args []js.Value) interface{} { return false }) )
var ( Stdout hackpadfs.File = &BufferedLogger{Nm: "dev/stdout", PrintFn: func(args ...any) { js.Global().Get("console").Call("log", args...) }} Stderr hackpadfs.File = &BufferedLogger{Nm: "dev/stderr", PrintFn: func(args ...any) { js.Global().Get("console").Call("error", args...) }} )
var ErrNotDir = WrapError(errors.New("not a directory"), "ENOTDIR")
var ModeBitTranslation = map[os.FileMode]uint32{ os.ModeDir: syscall.S_IFDIR, os.ModeCharDevice: syscall.S_IFCHR, os.ModeNamedPipe: syscall.S_IFIFO, os.ModeSymlink: syscall.S_IFLNK, os.ModeSocket: syscall.S_IFSOCK, }
Functions ¶
func BlockCount ¶
func ErrBadFile ¶
func ErrBadFileNumber ¶
func GetErrType ¶
GetErrType returns the JS type of the given error.
func JSBoolFunc ¶
func NewNullFile ¶
func NormPath ¶
NormPath normalizes the given path by cleaning it and making it non-rooted, as all go fs paths must be non-rooted.
Types ¶
type BufferedLogger ¶
type BufferedLogger struct { Nm string PrintFn func(args ...any) Mu sync.Mutex Buf bytes.Buffer TimerOnce sync.Once }
func (*BufferedLogger) Close ¶
func (b *BufferedLogger) Close() error
func (*BufferedLogger) Flush ¶
func (b *BufferedLogger) Flush()
func (*BufferedLogger) Name ¶
func (b *BufferedLogger) Name() string
func (*BufferedLogger) Print ¶
func (b *BufferedLogger) Print(s string) int
type FS ¶
FS represents a filesystem that implements the Node.js fs API. It is backed by a mount.FS, and automatically provides /dev/stdin, /dev/stdout, /dev/stderr, and /tmp. It can be configured with a default unix-style home directory backed by a persistent IndexedDB storage mechanism using FS.ConfigUnix.
func Config ¶
Config configures the given JavaScript object to be a filesystem that implements the Node.js fs API. It is the main entry point for code using jsfs. It returns the resulting FS, which should not typically be needed.
func (*FS) ConfigUnix ¶
ConfigUnix configures a standard unix-style home directory in the filesystem located at /home/me. It is backed by a persistent IndexedDB storage mechanism such that files will persist between browser sessions, and it is initialized to contain .data, Desktop, Documents, and Downloads directories.
func (*FS) GetFile ¶
GetFile fetches the file specified by the file descriptor that is the first of the given arguments.
type Func ¶
type Func interface { func(args []js.Value) (any, error) | func(args []js.Value) (any, any, error) }
Func is the type of a jsfs function.