datafs

package
v4.0.0-pre-2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnvFS = fsimpl.FSProviderFunc(NewEnvFS, "env")
View Source
var MergeFS = fsimpl.FSProviderFunc(NewMergeFS, "merge")
View Source
var StdinFS = fsimpl.FSProviderFunc(NewStdinFS, "stdin")
View Source
var WdFS = fsimpl.FSProviderFunc(
	func(u *url.URL) (fs.FS, error) {
		if !isSupportedPath(u.Path) {
			return nil, fmt.Errorf("unsupported path %q: %w", u.Path, fs.ErrInvalid)
		}

		vol, _, err := ResolveLocalPath(nil, u.Path)
		if err != nil {
			return nil, fmt.Errorf("resolve %q: %w", u.Path, err)
		}

		var fsys fs.FS
		if vol == "" || vol == "/" {
			fsys = osfs.NewFS()
		} else {
			var err error
			fsys, err = osfs.NewFS().SubVolume(vol)
			if err != nil {
				return nil, err
			}
		}

		return &wdFS{vol: vol, fsys: fsys}, nil
	},

	"file", "",
)

WdFS is a filesystem provider that creates local filesystems which support absolute paths beginning with '/', and interpret relative paths as relative to the current working directory (as reported by os.Getwd).

On Windows, certain types of paths are not supported, and will return an error. These are: - Drive Relative - e.g. C:foo\bar - Root Local - e.g. \\. or \\? - non-drive Local Devices - e.g. \\.\COM1, \\.\pipe\foo - NT Paths - e.g. \??\C:\foo\bar or \??\UNC\foo\bar

Functions

func ContextWithFSProvider

func ContextWithFSProvider(ctx context.Context, fsp fsimpl.FSProvider) context.Context

ContextWithFSProvider returns a context with the given FSProvider. Should only be used in tests.

func ContextWithStdin

func ContextWithStdin(ctx context.Context, r io.Reader) context.Context

func DirInfo

func DirInfo(name string, modTime time.Time) fs.FileInfo

DirInfo creates a fs.FileInfo for a directory with the given name. Use FileInfo to set other values.

func ExpandEnvFsys

func ExpandEnvFsys(fsys fs.FS, s string) string

ExpandEnvFsys - a convenience function intended for internal use only!

func FSProviderFromContext

func FSProviderFromContext(ctx context.Context) fsimpl.FSProvider

FSProviderFromContext returns the FSProvider from the context, if any

func FSysForPath

func FSysForPath(ctx context.Context, path string) (fs.FS, error)

FSysForPath returns an io/fs.FS for the given path (which may be an URL), rooted at /. A fsimpl.FSProvider is required to be present in ctx, otherwise an error is returned.

func FileInfo

func FileInfo(name string, size int64, mode fs.FileMode, modTime time.Time, contentType string) fs.FileInfo

FileInfo creates a static fs.FileInfo with the given properties. The result is also a fs.DirEntry and can be safely cast.

func FileInfoDirEntry

func FileInfoDirEntry(fi fs.FileInfo) fs.DirEntry

FileInfoDirEntry adapts a fs.FileInfo into a fs.DirEntry. If it doesn't already implement fs.DirEntry, it will be wrapped to always return the same fs.FileInfo.

func GetenvFsys

func GetenvFsys(fsys fs.FS, key string, def ...string) string

GetenvFsys - a convenience function intended for internal use only!

func NewEnvFS

func NewEnvFS(_ *url.URL) (fs.FS, error)

NewEnvFS returns a filesystem (an fs.FS) that can be used to read data from environment variables.

func NewMergeFS

func NewMergeFS(u *url.URL) (fs.FS, error)

NewMergeFS returns a new filesystem that merges the contents of multiple paths. Only a URL like "merge:" or "merge:///" makes sense here - the piped-separated lists of sub-sources to merge must be given to Open.

Usually you'll want to use WithDataSourcesFS to provide the map of datasources that can be referenced. Otherwise, only URLs will be supported.

An FSProvider will also be needed, which can be provided with a context using ContextWithFSProvider. Provide that context with fsimpl.WithContextFS.

func NewStdinFS

func NewStdinFS(_ *url.URL) (fs.FS, error)

NewStdinFS returns a filesystem (an fs.FS) that can be used to read data from standard input (os.Stdin).

func ResolveLocalPath

func ResolveLocalPath(fsys fs.FS, name string) (root, resolved string, err error)

ResolveLocalPath resolves a path on the given filesystem, relative to the current working directory, and returns both the root (/ or a volume name on Windows) and the resolved path. If the path is absolute (e.g. starts with a `/` or volume name on Windows), it is split and returned as-is. If fsys is nil, the current working directory is used. The output is suitable for use with io/fs functions.

func SplitFSMuxURL

func SplitFSMuxURL(in *url.URL) (*url.URL, string)

SplitFSMuxURL splits a URL into a filesystem URL and a relative file path

func StdinFromContext

func StdinFromContext(ctx context.Context) io.Reader

func WithDataSourcesFS

func WithDataSourcesFS(sources map[string]config.DataSource, fsys fs.FS) fs.FS

WithDataSourcesFS injects a datasource map into the filesystem fs, if the filesystem supports it (i.e. has a WithDataSources method). This is used for the mergefs filesystem.

func WrapWdFS

func WrapWdFS(fsys fs.FS) fs.FS

WrapWdFS is a filesystem wrapper that assumes non-absolute paths are relative to the current working directory (as reported by os.Getwd). It only works in a meaningful way when used with a local filesystem (e.g. os.DirFS or hackpadfs/os.FS).

func WrappedFSProvider

func WrappedFSProvider(fsys fs.FS, schemes ...string) fsimpl.FSProvider

WrappedFSProvider is an FSProvider that returns the given fs.FS

Types

This section is empty.

Jump to

Keyboard shortcuts

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