filesys

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

The filesys package implements drill.Node for the io/fs package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

type FS struct {
	fs.FS
	// contains filtered or unexported fields
}

FS wraps an fs.FS to implement drill.Node.

Included in FS are a number of FileHandlers. Any produced child FS will inherit these handlers.

In order to descend into a file, the file must have an extension that matches one of these handlers (according Handlers.Match). If there is a match, the handler is called, returning the node returned by the handler.

func NewFS

func NewFS(fsys fs.FS, handlers Handlers) (*FS, error)

NewFS returns an FS that wraps fsys, and includes a number of handlers. Returns an error if a handler pattern is malformed.

func (*FS) Fragment

func (f *FS) Fragment() string

Fragment returns the content of the file. Returns an empty string if the file does not exist, is a directory, or otherwise returns an error.

func (*FS) FragmentReader

func (f *FS) FragmentReader() (r io.ReadCloser, err error)

FragmentReader opens and returns the file.

func (*FS) Handlers

func (f *FS) Handlers() Handlers

Handlers returns a list of the Handlers used by the node.

func (*FS) Len

func (f *FS) Len() int

Len returns the number of files in the directory.

func (*FS) OrderedChild

func (f *FS) OrderedChild(i int) drill.Node

OrderedChild returns the file at index i from the results of fs.ReadDir.

func (*FS) OrderedChildren

func (f *FS) OrderedChildren() []drill.Node

OrderedChildren returns each file in the directory.

func (*FS) UnorderedChild

func (f *FS) UnorderedChild(name string) drill.Node

UnorderedChild returns the file matching name, or nil if it does not exist. Returns nil if the wrapped FS does not implement fs.SubFS.

func (*FS) UnorderedChildren

func (f *FS) UnorderedChildren() map[string]drill.Node

UnorderedChildren returns each file in the directory.

type Handler

type Handler struct {
	Pattern string
	Func    HandlerFunc
}

Handler maps a glob pattern to a HandlerFunc.

type HandlerFunc

type HandlerFunc func(fsys fs.FS, name string) drill.Node

HandlerFunc produces a drill.Node from the given file, usually by calling fsys.Open(name), and interpreting the contents of the file.

type Handlers

type Handlers []Handler

Handlers is an ordered list of Handler values.

func (Handlers) Match

func (hs Handlers) Match(file string) HandlerFunc

Match returns the first Handler for which the glob pattern matches file. Returns nil if no matches were found.

Directories

Path Synopsis
The markdown package implements filesys.Handler for the Markdown format.
The markdown package implements filesys.Handler for the Markdown format.

Jump to

Keyboard shortcuts

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