fs

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Separator    = '/'
	SeperatorStr = string(Separator)
)

Variables

View Source
var (
	ErrAlreadyExist = fmt.Errorf("already exists")
	ErrNotFound     = fmt.Errorf("not found")
	ErrInvalidName  = fmt.Errorf("invalid name")
	ErrNotSupported = fmt.Errorf("not supported")
	ErrDirNotEmpty  = fmt.Errorf("directory not empty")
)

Functions

func IsAbs

func IsAbs(s string) bool

Types

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

Dir is an abstraction of a directory

func (*Dir) Path

func (d *Dir) Path() string

Path returns absolute path to the dir.

func (*Dir) String

func (d *Dir) String() string

type File

type File struct {
	// contains filtered or unexported fields
}

File is an abstraction of a file.

func (*File) Path

func (f *File) Path() string

Path is the absolute path.

func (*File) Read

func (f *File) Read(writer io.Writer) (int64, error)

Read reads the file content as a stream and returns the number of bytes read.

func (*File) ReadAt

func (f *File) ReadAt(writer io.Writer, offset int) (int64, error)

ReadAt reads at a particular offset of the file. Returns number of bytes read.

func (*File) Size

func (f *File) Size() int64

Size of the file.

func (*File) String

func (f *File) String() string

func (*File) Write

func (f *File) Write(reader io.Reader) (int64, error)

Write appends to the file's content as a stream until io.EOF is encountered and returns the number of bytes written.

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

FileSystem is a thread-safe in-memory filesystem that allows basic operations. All public methods are thread-safe.

func New

func New() *FileSystem

New returns a new filesystem.

func (*FileSystem) ChangeDir

func (fs *FileSystem) ChangeDir(s string) error

ChangeDir switches current directory to s (relative/absolute)

func (*FileSystem) CurrentDir

func (fs *FileSystem) CurrentDir() string

CurrentDir returns the absolute path of the current directory

func (*FileSystem) Find

func (fs *FileSystem) Find(path, search string) ([]*File, []*Dir, error)

Find returns the list of files/dirs that match search given the path (relative/abs)

func (*FileSystem) FindFirstRegex

func (fs *FileSystem) FindFirstRegex(path, regex string) (string, error)

FindFirstRegex returns the first absolute path matching the regex for the given path (absolute/ relative)

func (*FileSystem) IsAbs

func (fs *FileSystem) IsAbs(s string) bool

func (*FileSystem) ListDir

func (fs *FileSystem) ListDir(s string) ([]*File, []*Dir, error)

ListDir lists all the files/dirs in s (relative/abs)

func (*FileSystem) MakeDir

func (fs *FileSystem) MakeDir(s string) error

MakeDir makes a new directory relative or absolute.

func (*FileSystem) Move

func (fs *FileSystem) Move(src, dst string) error

Move moves a file from src to dst. src/dst are relative or absolute.

func (*FileSystem) NewFile

func (fs *FileSystem) NewFile(s string) error

NewFile creates a new empty file at s (relative/absolute).

func (*FileSystem) Read

func (fs *FileSystem) Read(s string, writer io.Writer) (int64, error)

Read reads the file at s (relative/abs) and streams its content to writer.

func (*FileSystem) Remove

func (fs *FileSystem) Remove(s string) error

Remove removes s (relative/absolute) from the filesystem. It could be dir/file.

func (*FileSystem) Write

func (fs *FileSystem) Write(s string, reader io.Reader) (int64, error)

Write writes the what's in reader until EOF to the file s (relative/abs).

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

Metadata provides common metadata for files and directories.

func (*Metadata) AbsolutePath

func (md *Metadata) AbsolutePath() string

AbsolutePath return the absolute path of the dir/file. For dirs, we remove '/' except for the root.

func (*Metadata) Name

func (md *Metadata) Name() string

Returns the name of the node. For dirs, we trim suffix '/' for dirs)

func (*Metadata) Node

func (md *Metadata) Node() *trie.Node

type NodeType

type NodeType int

Type of the filesystem node

Jump to

Keyboard shortcuts

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