fs

package
v0.0.0-...-66fc070 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ModuleName = "fs"

ModuleName of the "fs" package

Variables

This section is empty.

Functions

func Enable

func Enable(runtime *goja.Runtime, registry *require.Registry, _ *require.RequireModule, currentWorkingDirectory string, fileSystem fs.FS)

Enable fs package

func Require

func Require(s *FS) func(runtime *goja.Runtime, module *goja.Object)

Require fs package

Types

type FS

type FS struct {

	// CurrentWorkingDirectory set in the process module. Not that this must NOT be used to prepend paths
	// but is rather to resolve files relative to CurrentWorkingDirectory when also a FileSystem is provided.
	// This achieves the effect that when FileSystem is used, the 'proper' structure of that fileystem is preserved.
	//
	// An example of this would be having an embed.FS which is a directory containing the ruleset:
	// go-embed testdata
	// var fs embed.FS
	//
	// On the process module, the CurrentWorkingDirectory is set and provides the Cwd method. The JavaScript code
	// already uses this on paths that are then provided to fs so the CurrentWorkingDirectory is already part of that
	// This directory however most likely doesn't exist in embedded so that prefix is then stripped of such that
	// the ruleset can still be referenced now using testdata/ruleset.yaml
	CurrentWorkingDirectory string

	// FileSystem if not nil is used to resolve e.g. embedded filesystems (embed.FS). These can contain bundled
	// OpenAPI specs and/or rulesets. The files are resolved by trimming the CurrentWorkingDirectory prefix
	// from paths and if there is a match that file is used. In case of no match, the search continues on the
	// system file system using os.ReadFile.
	FileSystem fs.FS
	// contains filtered or unexported fields
}

FS struct initialization

func (*FS) LStat

func (f *FS) LStat(call goja.FunctionCall) goja.Value

LStat translated to os.Lstat but returning false for isDirectory isSymbolicLink isBlockDevice isCharacterDevice isFIFO isSocket and always true for isFile. Note that this most likely breaks glob patterns with directories and this method should be properly implemented TODO fix LStat such that the returned values are correct for also directories / symlinks

func (*FS) Native

func (f *FS) Native(_ goja.FunctionCall) goja.Value

Native asynchronous realpath. Not implemented

func (*FS) PromiseReadFile

func (f *FS) PromiseReadFile(call goja.FunctionCall) goja.Value

PromiseReadFile using os.ReadFile

func (*FS) ReadFile

func (f *FS) ReadFile(call goja.FunctionCall) goja.Value

ReadFile with callback

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL