fs

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// Path is the absolute path to the file or directory (relative to the root
	// of the file system).
	Path string
	// contains filtered or unexported fields
}

Node represents a file or directory in the file system.

func (*Node) IsDir

func (p *Node) IsDir() (bool, error)

IsDir reports whether the entry describes a directory.

func (*Node) ModTime

func (p *Node) ModTime() (time.Time, error)

ModTime returns the modification time of the file.

func (*Node) Mode

func (p *Node) Mode() (fs.FileMode, error)

Mode returns file mode bits.

func (*Node) Name

func (p *Node) Name() (string, error)

Name returns the name of the file (or subdirectory) described by the entry. This name is only the final element of the path (the base name), not the entire path. For example, Name would return "hello.go" not "home/gopher/hello.go".

func (*Node) Size

func (p *Node) Size() (int64, error)

Size returns the size of the file in bytes. If the file is a directory, the size is system-dependent and should not be used.

func (*Node) Sys

func (p *Node) Sys() (any, error)

Sys returns the underlying data source (can return nil).

func (*Node) Type

func (p *Node) Type() (fs.FileMode, error)

Type returns the type bits for the entry. The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.

type NodeSet

type NodeSet struct {
	Data iter.Seq[*Node]
	Base fs.FS
	Err  error
}

NodeSet represents a set of file system nodes, along with any error that occurred while retrieving them.

func Dir

func Dir(dir string) NodeSet

Dir returns a NodeSet for the specified directory.

func New

func New(root fs.FS) NodeSet

New creates a NodeSet for the provided file system, starting with the root node.

func Nodes

func Nodes(root fs.FS, nodes ...*Node) NodeSet

Nodes creates a NodeSet containing the provided nodes.

func Root

func Root(root fs.FS, doc *Node) NodeSet

Root creates a NodeSet containing the provided root node.

func (NodeSet) All

func (p NodeSet) All() NodeSet

All returns a NodeSet containing all nodes. It's a cache operation for performance optimization when you need to traverse the nodes multiple times.

func (NodeSet) Collect

func (p NodeSet) Collect() ([]*Node, error)

Collect retrieves all nodes from the NodeSet.

func (NodeSet) Dir

func (p NodeSet) Dir() NodeSet

Dir returns a NodeSet containing all child nodes of the nodes in the NodeSet that are directories.

func (NodeSet) File

func (p NodeSet) File() NodeSet

File returns a NodeSet containing all child nodes of the nodes in the NodeSet that are files (not directories).

func (NodeSet) First

func (p NodeSet) First() (*Node, error)

First returns the first node in the NodeSet.

func (NodeSet) IsDir

func (p NodeSet) IsDir() (is bool, err error)

IsDir reports whether the first node in the NodeSet is a directory.

func (NodeSet) Match

func (p NodeSet) Match(pattern string) NodeSet

Match returns a NodeSet containing all child nodes of the nodes in the NodeSet that match the specified pattern. The pattern syntax is the same as in path.Match. For example, "file*.txt" matches "file1.txt" and "file2.txt", but not "myfile.txt".

func (NodeSet) ModTime

func (p NodeSet) ModTime() (modTime time.Time, err error)

ModTime returns the modification time of the first node in the NodeSet.

func (NodeSet) Mode

func (p NodeSet) Mode() (mode fs.FileMode, err error)

Mode returns the file mode of the first node in the NodeSet.

func (NodeSet) Name

func (p NodeSet) Name() (name string, err error)

Name returns the name of the first node in the NodeSet.

func (NodeSet) Ok

func (p NodeSet) Ok() bool

Ok returns true if there is no error in the NodeSet.

func (NodeSet) OnError

func (p NodeSet) OnError(onErr func(error) bool) NodeSet

OnError calls onErr for any error in the NodeSet and returns a new NodeSet without the nodes that have errors. If onErr returns false, it stops processing and returns a NodeSet without the remaining nodes.

func (NodeSet) One

func (p NodeSet) One() NodeSet

One returns a NodeSet containing the first node. It's a performance optimization when you only need the first node (stop early).

func (NodeSet) Path

func (p NodeSet) Path() (name string, err error)

Path returns the path of the first node in the NodeSet. The path is the absolute path to the file or directory (relative to the root of the file system). Note the path is not started with a slash. For example, if the root of the file system is "/home/gopher" and the node represents the file "/home/gopher/a/b.go", Path would return "a/b.go". For the root node, Path would return "" (not "/").

func (NodeSet) Single

func (p NodeSet) Single() NodeSet

Single returns a NodeSet containing the single node. If there are zero or more than one nodes, it returns an error. ErrNotFound or ErrMultiEntities is returned accordingly.

func (NodeSet) Size

func (p NodeSet) Size() (size int64, err error)

Size returns the size of the first node in the NodeSet.

func (NodeSet) XGo_Any

func (p NodeSet) XGo_Any(name string) NodeSet

XGo_Any returns a NodeSet containing all descendant nodes (including the nodes themselves) with the specified name. If name is "file", it returns all file nodes. If name is "dir", it returns all directory nodes. If name is "", it returns all nodes.

  • .**.file
  • .**.dir
  • .**.*

func (NodeSet) XGo_Child

func (p NodeSet) XGo_Child() NodeSet

XGo_Child returns a NodeSet containing all child nodes of the nodes in the NodeSet.

func (NodeSet) XGo_Enum

func (p NodeSet) XGo_Enum() iter.Seq[NodeSet]

XGo_Enum returns an iterator over the nodes in the NodeSet.

func (NodeSet) XGo_first

func (p NodeSet) XGo_first() (ret *Node, err error)

_first returns the first node in the NodeSet. It's required by XGo compiler.

Jump to

Keyboard shortcuts

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