quickfs

package
v2.4.9 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileLikeExcluded = errors.New("file like object was excluded")
)

Functions

func IsText

func IsText[T string | []byte](data T) bool

func IsTextReader

func IsTextReader(r io.Reader) bool

func PrintRoot

func PrintRoot(w io.Writer, root *FSDirectory) int

func PrintRootFn

func PrintRootFn(w io.Writer, root *FSDirectory, indentString string, wrap func(int, FileLike) string) int

Types

type Directory

type Directory interface {
	FileLike

	// Find a directory by path.
	Find(path []string) (FileLike, error)

	// Traverse traverses the directory tree.
	// It will traverse into subdirectories.
	Traverse(fn func(FileLike) (cancel bool, err error)) (cancel bool, err error)

	// ForEach loops over all directories and files in this directory.
	// This will not traverse into subdirectories and is not recursive.
	// execRoot will let execute the function on the directory itself if true (as well as its direct children)
	ForEach(execRoot bool, fn func(FileLike) (cancel bool, err error)) (cancel bool, err error)

	// Load loads the directory content.
	Load() error
}

func NewDirectory

func NewDirectory(name, path string) Directory

NewFSDirectory creates a new FSDirectory.

type FSDirectory

type FSDirectory struct {
	// Name of the directory.
	Name string

	// Path of the directory.
	Path string

	// Files in the directory.
	Files *orderedmap.OrderedMap[string, *FSFile]

	// Directories in the directory.
	Directories *orderedmap.OrderedMap[string, *FSDirectory]

	// IsExcluded returns true if the directory is excluded.
	// It should only be set on the root directory.
	IsExcluded func(FileLike) bool
	// contains filtered or unexported fields
}

func NewFSDirectory

func NewFSDirectory(name, dirPath string, root *FSDirectory) *FSDirectory

func (*FSDirectory) AddDirectory

func (d *FSDirectory) AddDirectory(dirPath string)

func (*FSDirectory) AddFile

func (d *FSDirectory) AddFile(filePath string, reader io.ReadCloser) *FSFile

func (*FSDirectory) Find

func (d *FSDirectory) Find(path []string) (FileLike, error)

func (*FSDirectory) FindWithParent

func (d *FSDirectory) FindWithParent(path []string) (*FSDirectory, FileLike, error)

func (*FSDirectory) ForEach

func (d *FSDirectory) ForEach(execRoot bool, fn func(FileLike) (cancel bool, err error)) (cancel bool, err error)

ForEach loops over all directories and files in this directory. This will not traverse into subdirectories and is not recursive.

func (*FSDirectory) GetName

func (d *FSDirectory) GetName() string

func (*FSDirectory) GetPath

func (d *FSDirectory) GetPath() string

func (*FSDirectory) IsDir

func (f *FSDirectory) IsDir() bool

func (*FSDirectory) Load

func (d *FSDirectory) Load() error

func (*FSDirectory) Root

func (d *FSDirectory) Root() *FSDirectory

Root returns the root directory.

func (*FSDirectory) Size added in v2.3.5

func (d *FSDirectory) Size() int64

func (*FSDirectory) String

func (d *FSDirectory) String() string

String returns the directory in string format.

func (*FSDirectory) Traverse added in v2.3.5

func (d *FSDirectory) Traverse(fn func(FileLike) (cancel bool, err error)) (cancel bool, err error)

Traverse traverses the directory tree. It will traverse into subdirectories.

type FSFile

type FSFile struct {
	// Name of the file.
	Name string

	// Path of the file.
	Path string

	// Size of the file.
	Size int64

	// If the file is all valid utf-8 text.
	IsText bool

	Reader io.ReadCloser
}

func NewFSFile

func NewFSFile(name, path string, root *FSDirectory) (*FSFile, error)

NewFSFile creates a new FSFile. If root is not nil, it will check if the file is excluded. The file must always be closed after calling this function.

func (*FSFile) Close

func (f *FSFile) Close() error

func (*FSFile) GetName

func (f *FSFile) GetName() string

func (*FSFile) GetPath

func (f *FSFile) GetPath() string

func (*FSFile) IsDir

func (f *FSFile) IsDir() bool

func (*FSFile) Read

func (f *FSFile) Read(p []byte) (n int, err error)

type File

type File interface {
	FileLike

	// Read reads the file content.
	io.Reader
}

func NewFile

func NewFile(name, path string) (File, error)

NewFSFile creates a new FSFile.

type FileLike

type FileLike interface {
	// Name returns the name of the file.
	GetName() string

	// Path returns the path of the file.
	GetPath() string

	// IsDir returns true if the file is a directory.
	IsDir() bool
}

Jump to

Keyboard shortcuts

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