em_file

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtraDataContentSeed = "content_seed"
)

Variables

This section is empty.

Functions

func CreateFolder

func CreateFolder(root Node, path string) bool

Create folders. returns false if failed to create.

func DeleteEmptyFolders

func DeleteEmptyFolders(folder Folder)

func Display

func Display(l esl.Logger, node Node)

func MaxDepth

func MaxDepth(node Node) int

func SumFileSize

func SumFileSize(node Node) int64

func SumNumFiles

func SumNumFiles(node Node) int

func SumNumNode

func SumNumNode(node Node) int

Types

type File

type File interface {
	Node

	// Size of the file.
	Size() int64

	// Modified time.
	ModTime() time.Time

	// Content of the file.
	Content() []byte

	// Update content
	UpdateContent(newSeed, newSize int64)

	// Update mod time
	UpdateTime(t time.Time)

	// Clone this instance
	Clone() File
}

func NewFile

func NewFile(name string, size int64, mtime time.Time, contentSeed int64) File

type Folder

type Folder interface {
	Node

	// Returns descendant nodes.
	Descendants() []Node

	// Add node under this folder.
	// This will replace existing node by name.
	Add(node Node)

	// Delete node by name. Returns false if the node not found.
	Delete(name string) bool

	// Compare nodes and descendants.
	DeepEquals(x Node) bool

	// Number of files. Does not include files under descendants
	NumFiles() int

	// Number of folders. Does not include folders under descendants
	NumFolders() int
}

func DemoTree

func DemoTree() Folder

Returns demo tree like below ``` root

|-- a (folder)
    |-- x (file)
    |-- y (file)
    |-- b (empty folder)
    |-- c (folder)
        |-- z (file)

```

func NewFolder

func NewFolder(name string, descendant []Node) Folder

type Node

type Node interface {
	// Name of the node.
	Name() string

	// Node type
	Type() NodeType

	// Compare nodes.
	Equals(x Node) bool

	// Extra data for serialize node state
	ExtraData() map[string]interface{}

	// Rename this node
	Rename(newName string)
}

func ResolvePath

func ResolvePath(node Node, path string) Node

Returns a Node of the path. Returns nil if the node not found for the path.

type NodeType

type NodeType string
const (
	FileNode   NodeType = "file"
	FolderNode NodeType = "folder"
)

Jump to

Keyboard shortcuts

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