vio

package
v0.0.0-...-79a645e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNodeNotFound = errors.New("node not found")

ErrNodeNotFound is returned when attempting to look up a node within a FileTree that does not exist.

View Source
var ErrSkip = errors.New("skip")

ErrSkip can be passed as the result from a WalkFunc to tell FileTree.Walk to skip the remainder of the directory.

View Source
var Zeroes = io.Reader(&zeroesReader{})

Functions

func Info

func Info(f File) os.FileInfo

Info produces an implementation of os.FileInfo from a an implementation of File.

func LazyReadCloser

func LazyReadCloser(openFunc func() (io.Reader, error),
	closeFunc func() error) io.ReadCloser

LazyReadCloser is an implementation of io.ReadCloser that defers its own initialization until the first attempted read.

func WriteSeeker

func WriteSeeker(w io.Writer) (io.WriteSeeker, error)

Types

type ArchiveFunc

type ArchiveFunc func(path string, f File) error

ArchiveFunc is the type of function called for each file or directory immediately before it is streamed into an archive with the FileTree.Archive function.

type CustomFileArgs

type CustomFileArgs struct {
	Name               string
	Size               int
	ModTime            time.Time
	IsDir              bool
	IsSymlink          bool
	IsSymlinkNotCached bool
	Symlink            string
	ReadCloser         io.ReadCloser
}

CustomFileArgs takes all elements that need to be provided to the CustomFile function.

type File

type File interface {

	// Name returns the base name of the file, not a
	// full path (see filepath.Base).
	Name() string

	// Size returns the size of the file in bytes. If
	// the file represents a directory the size returned
	// should be zero.
	Size() int

	// ModTime returns the time the file was most
	// recently modified.
	ModTime() time.Time

	// Read implements io.Reader to retrieve file
	// contents.
	Read(p []byte) (n int, err error)

	// Close implements io.Closer.
	Close() error

	// IsDir returns true if the File represents a
	// directory.
	IsDir() bool

	// IsSymlink returns true if the File represents a symlink.
	IsSymlink() bool

	// SymlinkIsCached returns true if the symlink can be read without messing with a filetree order.
	SymlinkIsCached() bool

	// Symlink returns a non-empty string if the symlink is cached, or an empty string otherwise.
	Symlink() string
}

File represents a file from the filesystem.

func CustomFile

func CustomFile(args CustomFileArgs) File

CustomFile makes it possible to construct a custom file that implements the File interface without necessarily being backed by an actual file on the filesystem.

func LazyOpen

func LazyOpen(path string) (File, error)

LazyOpen is an alternative implementation of Open that defers actually opening the file until the first attempted read.

func Open

func Open(path string) (File, error)

Open mimics the os.Open function but returns an implementation of File.

type FileTree

type FileTree interface {
	Close() error

	// Archive encodes the data within the FileTree into
	// a stream that it writes to w. This stream can be
	// decoded by calling LoadArchive.
	//
	// The fn argument is optional, and can be used to
	// track progress or perform logging during the
	// archiving process.
	Archive(w io.Writer, fn ArchiveFunc) error

	// Map adds f to the FileTree at path. It automatically
	// creates parent directories (recursively) if necessary,
	// and it automatically replaces any existing nodes
	// within the tree if there are collisions, calling
	// the Close method recursively on all replaced
	// nodes.
	//
	// Mapping a directory over an existing directory
	// node does not delete all existing nodes under the
	// directory, but instead merges over the top of
	// them, only replacing nodes with the same name.
	Map(path string, f File) error

	// MapSubTree adds t to the FileTree as a sub-tree
	// at path. It automatically creates parent directories
	// (recursively) if necessary, and it automatically
	// replaces any existing nodes within the tree if
	// there are collisions, calling the Close
	// method recursively on all replaced nodes.
	MapSubTree(path string, t FileTree) error

	// SubTree returns a new FileTree object where the
	// root node is the directory node at path.
	SubTree(path string) (FileTree, error)

	// Unmap removes a node from the FileTree, calling
	// the Close method recursively on all removed
	// nodes.
	Unmap(path string) error

	// Walk traverses the FileTree recursively in a
	// pre-order tree traversal.
	Walk(fn WalkFunc) error

	// WalkNode traverses the FileTree recursively and
	// passes in a complete tree node so we can learn
	// more about it's place in the tree.
	WalkNode(fn WalkNodeFunc) error

	NodeCount() int
}

FileTree represents a tree of files and directories it is used to organize, modify, and transfer the data that will become the filesystem for an application.

func FileTreeFromDirectory

func FileTreeFromDirectory(dir string) (FileTree, error)

FileTreeFromDirectory creates a new FileTree based on a directory. The files in the tree will be loaded in lazily, so the function should be safe for use on very large directory trees.

func LoadArchive

func LoadArchive(r io.Reader) (FileTree, error)

LoadArchive reads a stream of data created by the FileTree.Archive function and loads it as a new FileTree. This can be used for storing FileTrees or transferring them over the network.

LoadArchive loads the FileTree using lazy loading, and does not need to cache the entire contents of r within memory.

func NewFileTree

func NewFileTree() FileTree

NewFileTree returns a new filetree with an empty root directory.

type TreeNode

type TreeNode struct {
	File               File
	Parent             *TreeNode
	Children           []*TreeNode
	NodeSequenceNumber int64
	Links              int
}

TreeNode is the structure that all nodes in a FileTree are built on.

func (*TreeNode) MarshalJSON

func (n *TreeNode) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*TreeNode) Path

func (n *TreeNode) Path() string

type WalkFunc

type WalkFunc func(path string, f File) error

WalkFunc is the type of function called for each file or directory visited by FileTree.Walk. The root node will have path ".", and all other nodes will be built from that (e.g. "./a").

type WalkNodeFunc

type WalkNodeFunc func(path string, n *TreeNode) error

WalkNodeFunc is the type of function called for each node visited by FileTree.WalkNode.

Jump to

Keyboard shortcuts

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