fs

package
v0.0.0-...-f64633d Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(ctx Context, dst chan<- Item, src <-chan Item) bool

Copy copies one item and all its contents from src to dst. It reports whether the stream is still active (the caller should quit if not).

func Entries

func Entries(ctx context.Context, c <-chan Item) <-chan ItemInfo

func Filter

func Filter(ctx context.Context, src <-chan Item, accept func(Item) bool) <-chan Item

func Walk

func Walk(ctx Context, path string, blockSize int) <-chan Item

Types

type Answer

type Answer int
const (
	// Quit requests the sender to stop sending data.
	Quit Answer = iota
	// Down requests the sender to show the contents
	// of the item. This should only be used to reply
	// to directory entry items.
	Down
	// Next requests that the sender send the next
	// item without descending into it.
	Next
	// Skip requests that the sender skip over
	// all remaining items in the current file or directory.
	Skip
)

type Context

type Context interface {
	context.Context
	Report(err error)
}

type FS

type FS <-chan Item

type Item

type Item struct {
	// Dir holds information about a file.
	// It is nil when sending a file's data.
	Dir os.FileInfo

	// Path holds the full path of the item, or the empty string
	// if Dir is nil.
	Path string

	// Data holds a file's data block.
	Data []byte

	// Answer must be used to send a reply
	// to the item.
	Reply chan<- Answer
}

Item represents an item of filesystem data. If Dir is non-nil, the item represents a directory entry. If Data is non-empty, the item represents a data block.

When an item is received, the receiver is expected to send on the reply channel to indicate the next thing for the sender to do.

func (Item) IsEnd

func (it Item) IsEnd() bool

IsEnd reports whether the given item represents to end of a sequence of data or directory entries.

func (Item) WithReply

func (it Item) WithReply(r chan<- Answer) Item

WithReply returns it with its reply channel set to r.

type ItemInfo

type ItemInfo struct {
	Path  string
	Dir   os.FileInfo
	Depth int
}

Jump to

Keyboard shortcuts

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