quickfs

package
v2.2.7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: GPL-2.0 Imports: 12 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 added in v2.2.7

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(path []string) (FileLike, error)

	ForEach(func(FileLike) (cancel bool, err error)) (cancel bool, err error)

	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 map[string]File

	// Directories in the directory.
	Directories map[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 added in v2.2.7

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

func (*FSDirectory) ForEach

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

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) String

func (d *FSDirectory) String() string

String returns the directory in string format.

type FSFile

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

	// Path of the file.
	Path string

	// 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