filesystem

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: GPL-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchAnd

func MatchAnd(matches ...func(filepath string) bool) func(filepath string) bool

MatchAnd returns a matcher-func that matches a file if all the given matchers match.

It can be passed any number of matchers.

This allows for more complex logic when matching paths.

func MatchExt

func MatchExt(extension string) func(path string) bool

MatchExt returns a matcher-func that matches a file if the given extension matches the file path.

The extension passed to this function is normalized to start with a ".".

When matching, the extension is retrieved from the file path with filepath.Ext and compared to the provided extension.

func MatchNever

func MatchNever(string) bool

MatchNever returns a matcher-func that never matches any file.

func MatchOr

func MatchOr(matches ...func(filepath string) bool) func(filepath string) bool

MatchOr returns a matcher-func that matches a file if any of the given matchers match.

It can be passed any number of matchers.

This allows for more complex logic when matching paths.

func MatchPrefix

func MatchPrefix(prefix string) func(filepath string) bool

MatchPrefix returns a matcher-func that matches a file if the given prefix matches the file path.

The prefix is normalized to use "/" as the path separator.

If the prefix is not empty and does not end with a "." or "/", it is appended with a "/".

When matching, the file path is compared to the prefix, the provided path either has to be the prefix or start with the prefix.

func MatchSuffix

func MatchSuffix(suffix string) func(path string) bool

MatchSuffix returns a matcher-func that matches a file if the given suffix matches the file path.

The suffix is normalized to use "/" as the path separator.

If the suffix is not empty and does not start with a "." or "/", it is prepended with a "/".

When matching, the file path is compared to the suffix, the provided path either has to be the suffix or end with the suffix.

func Sub

func Sub(fileSys fs.FS, path string) fs.FS

Types

type FileHeader

type FileHeader interface {
	Name() string
	Size() int64
	Open() (multipart.File, error)
}

type MatchFS

type MatchFS struct {
	// contains filtered or unexported fields
}

MatchFS is a filesystem that only allows opening files that match a given matcher-func.

It can be used to restrict access to files in a filesystem.

The matcher-func is called with the path of the file that is being opened.

func NewMatchFS

func NewMatchFS(fs fs.FS, matches func(filepath string) bool) *MatchFS

NewMatchFS creates a new MatchFS filesystem that wraps the given filesystem and only allows opening files that match the given matcher-func.

func (*MatchFS) FS

func (m *MatchFS) FS() fs.FS

FS returns the underlying filesystem that is being wrapped by the MatchFS.

func (*MatchFS) ForceOpen

func (m *MatchFS) ForceOpen(name string) (fs.File, error)

ForceOpen opens the file at the given path, even if it does not match the matcher-func.

This allows for bypassing any restrictions that the matcher-func might impose.

func (*MatchFS) Open

func (m *MatchFS) Open(name string) (fs.File, error)

Open opens the file at the given path if the path matches the matcher-func.

func (*MatchFS) ReadDir

func (m *MatchFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the directory at the given path.

It returns the list of files in the directory if the path matches the matcher-func.

type MultiFS

type MultiFS struct {
	// contains filtered or unexported fields
}

MultiFS is a filesystem that combines multiple filesystems.

It can be used to combine multiple filesystems into a single filesystem.

When opening a file, it will try to open the file in each filesystem in the order they were added.

It is best (and automatically) used with the `MatchFS` filesystem to restrict access to files in the filesystems.

This allows for faster skipping of filesystems that do not contain the file.

func NewMultiFS

func NewMultiFS(fileSystems ...fs.FS) *MultiFS

NewMultiFS creates a new MultiFS filesystem that combines the given filesystems.

If no filesystems are given, an empty MultiFS filesystem is created.

func (*MultiFS) Add

func (m *MultiFS) Add(fs fs.FS, matches func(filepath string) bool)

Add adds the given filesystem to the MultiFS filesystem.

If a matcher-func is given, it will only allow opening files that match the given matcher-func.

This allows for restricting access to files in the filesystem.

A regular `fs.FS` is added to the pool if no matcher-func is given.

func (*MultiFS) FS

func (m *MultiFS) FS() []fs.FS

FS returns the list of filesystems that are being combined by the MultiFS.

func (*MultiFS) ForceOpen

func (m *MultiFS) ForceOpen(name string) (fs.File, error)

ForceOpen opens the file at the given path, even if it does not match the matcher-func.

This allows for bypassing any restrictions that the matcher-func of any underlying `MatchFS` might impose.

func (*MultiFS) Open

func (m *MultiFS) Open(name string) (fs.File, error)

Open opens the file at the given path.

It will try to open the file in each filesystem in the order they were added.

func (*MultiFS) ReadDir

func (m *MultiFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the directory at the given path.

It returns the list of files in the provided directory (if any).

Directories

Path Synopsis
fs

Jump to

Keyboard shortcuts

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