Documentation ¶
Overview ¶
Package dir provides support for folder operations within the 0g storage client. Since the 0g storage node does not natively support folder operations, this package introduces a way to represent and manage hierarchical directory structures, including encoding, decoding, and comparing directories and files. The folder structure is serialized into a binary format that includes a JSON representation of the data, which can be stored on and retrieved from the 0g storage node.
The main features of this package include:
- Defining the FsNode structure, which models files and directories in a nested, hierarchical format.
- Serializing an FsNode structure into a binary format that includes a JSON representation, suitable for storage on a 0g storage node.
- Deserializing the binary format back into an FsNode structure for further manipulation and operations.
- Supporting the comparison of two directory structures to identify differences such as added, removed, or modified files.
This package enables the 0g storage client to manage complex directory structures using an efficient and extensible data format, facilitating advanced file system operations beyond single file storage.
Index ¶
- Variables
- func PrettyPrint(root *DiffNode)
- type DiffNode
- type DiffStatus
- type FileType
- type FsNode
- func (node *FsNode) Equal(rhs *FsNode) bool
- func (node *FsNode) Flatten(filterFunc ...func(*FsNode) bool) (result []*FsNode, relpaths []string)
- func (node *FsNode) Locate(path string) (*FsNode, error)
- func (node *FsNode) MarshalBinary() ([]byte, error)
- func (node *FsNode) Search(fileName string) (*FsNode, bool)
- func (node *FsNode) Traverse(actionFunc func(node *FsNode, relativePath string) error) error
- func (node *FsNode) UnmarshalBinary(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( CodecVersion = uint16(1) CodecMagicBytes = crypto.Keccak256([]byte("0g-storage-client-dir-codec")) )
Functions ¶
func PrettyPrint ¶
func PrettyPrint(root *DiffNode)
PrettyPrint prints the DiffNode tree in a human-readable format with a tree skeleton structure.
Types ¶
type DiffNode ¶
type DiffNode struct { Node *FsNode // The original node Status DiffStatus // Diff status of the node Entries *btree.BTreeG[*DiffNode] // Directory entries as a B-Tree }
DiffNode represents a node in the diff structure with its status.
func NewDiffNode ¶
func NewDiffNode(node *FsNode, status DiffStatus) *DiffNode
NewDiffNode creates a new DiffNode.
type DiffStatus ¶
type DiffStatus string
DiffStatus represents the status of a node in the diff.
const ( DiffStatusAdded DiffStatus = "added" DiffStatusRemoved DiffStatus = "removed" DiffStatusModified DiffStatus = "modified" DiffStatusUnchanged DiffStatus = "unchanged" )
type FsNode ¶
type FsNode struct { Name string `json:"name"` // File or directory name Type FileType `json:"type"` // File type of the node Root string `json:"hash,omitempty"` // Merkle root hash (only for regular files) Size int64 `json:"size,omitempty"` // File size in bytes (only for regular files) Link string `json:"link,omitempty"` // Symbolic link target (only for symbolic links) Entries []*FsNode `json:"entries,omitempty"` // Directory entries (only for directories) }
FsNode represents a node in the filesystem hierarchy.
func BuildFileTree ¶
BuildFileTree recursively builds a file tree for the specified directory.
func NewDirFsNode ¶
NewDirFsNode creates a new FsNode representing a directory.
func NewFileFsNode ¶
NewFileFsNode creates a new FsNode representing a regular file.
func NewSymbolicFsNode ¶
NewSymbolicFsNode creates a new FsNode representing a symbolic link.
func (*FsNode) Flatten ¶
Flatten recursively flattens the FsNode tree into a slice of FsNode pointers and a slice of relative paths. The filterFunc is applied to each node to determine if it should be included in the result.
func (*FsNode) Locate ¶
Locate finds a sub-node within the FsNode tree based on the given path. The path can be a file or directory, and it should be relative to the current node.
func (*FsNode) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface. It encodes the FsNode into a binary format.
func (*FsNode) Traverse ¶
Traverse recursively traverses the FsNode tree and applies the provided actionFunc to each node. This method only requires the user to handle relative paths.
Parameters:
- actionFunc: A function that defines the action to perform on each node. The function takes the current node and its relative path as arguments. This function can perform any necessary operations, such as collecting nodes, uploading files, or logging information.
func (*FsNode) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. It decodes the FsNode from a binary format.