node

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2015 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package node represents the Amazon Cloud Drive nodes documented at https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes It also provides the Tree struct which allows you to refer to the entire filesystem as a file tree as defined by the Amazon documentation.

Index

Constants

This section is empty.

Variables

View Source
var (

	// Mocked is a valid tree (mock). The IDs are the fully-qualified path of
	// the file or folder to make testing easier.
	// /
	// |-- README.md
	// |-- pictures
	// |-- |
	//     | -- logo.png
	Mocked = &Tree{
		Node: rootNode,
		nodeMap: map[string]*Node{
			"/":                  rootNode,
			"/README.md":         rootNode.Nodes[0],
			"/pictures":          rootNode.Nodes[1],
			"/pictures/logo.png": rootNode.Nodes[1].Nodes[0],
		},
	}
)

Functions

This section is empty.

Types

type ContentProperties

type ContentProperties struct {
	Version     uint64    `json:"version,omitempty"`
	Extension   string    `json:"extension,omitempty"`
	Size        uint64    `json:"size,omitempty"`
	MD5         string    `json:"md5,omitempty"`
	ContentType string    `json:"contentType,omitempty"`
	ContentDate time.Time `json:"contentDate,omitempty"`
}

ContentProperties hold the properties of the node.

type Node

type Node struct {
	// Coming from Amazon
	ID                string            `json:"id,omitempty"`
	Name              string            `json:"name,omitempty"`
	Kind              string            `json:"kind,omitempty"`
	Parents           []string          `json:"Parents,omitempty"`
	Status            string            `json:"status,omitempty"`
	Labels            []string          `json:"labels,omitempty"`
	CreatedBy         string            `json:"createdBy,omitempty"`
	CreationDate      time.Time         `json:"creationDate,omitempty"`
	ModifiedDate      time.Time         `json:"modifiedDate,omitempty"`
	Version           uint64            `json:"version,omitempty"`
	TempLink          string            `json:"tempLink,omitempty"`
	ContentProperties ContentProperties `json:"contentProperties,omitempty"`

	// Internal
	Nodes Nodes `json:"nodes,omitempty"`
	Root  bool  `json:"root,omitempty"`
	// contains filtered or unexported fields
}

Node represents a digital asset on the Amazon Cloud Drive, including files and folders, in a parent-child relationship. A node contains only metadata (e.g. folder) or it contains metadata and content (e.g. file).

func (*Node) AddChild

func (n *Node) AddChild(child *Node)

AddChild add a new child for the node

func (*Node) Available

func (n *Node) Available() bool

Available returns true if the node is available

func (*Node) CreateFolder

func (n *Node) CreateFolder(name string) (*Node, error)

CreateFolder creates the named folder under the node

func (*Node) Download

func (n *Node) Download() (io.ReadCloser, error)

Download downloads the node and returns the body as io.ReadCloser or an error. The caller is responsible for closing the reader.

func (*Node) IsAsset

func (n *Node) IsAsset() bool

IsAsset returns whether the node represents an asset.

func (*Node) IsDir

func (n *Node) IsDir() bool

IsDir returns whether the node represents a folder.

func (*Node) IsFile

func (n *Node) IsFile() bool

IsFile returns whether the node represents a file.

func (*Node) ModTime

func (n *Node) ModTime() time.Time

ModTime returns the last modified time of the node.

func (*Node) Overwrite

func (n *Node) Overwrite(r io.Reader) error

Overwrite writes contents of r as name inside the current node.

func (*Node) Remove

func (n *Node) Remove() error

Remove deletes a node from the server. This function does not update the NodeTree, the caller should do so!

func (*Node) RemoveChild

func (n *Node) RemoveChild(child *Node)

RemoveChild remove a new child for the node

func (*Node) Size

func (n *Node) Size() int64

Size returns the size of the node.

func (*Node) Upload

func (n *Node) Upload(name string, r io.Reader) (*Node, error)

Upload writes contents of r as name inside the current node.

type Nodes

type Nodes []*Node

Nodes is a slice of nodes

type Tree

type Tree struct {
	*Node

	// Internal
	LastUpdated time.Time
	Checkpoint  string
	// contains filtered or unexported fields
}

Tree represents a node tree.

func NewTree

func NewTree(c client, cacheFile string) (*Tree, error)

NewTree returns the root node (the head of the tree).

func (*Tree) Close

func (nt *Tree) Close() error

Close finalizes the NodeTree

func (*Tree) FindByID

func (nt *Tree) FindByID(id string) (*Node, error)

FindByID returns the node identified by the ID.

func (*Tree) FindNode

func (nt *Tree) FindNode(path string) (*Node, error)

FindNode finds a node for a particular path. TODO(kalbasit): This does not perform well, this should be cached in a map path->node and calculated on load (fresh, cache, refresh).

func (*Tree) MkdirAll

func (nt *Tree) MkdirAll(path string) (*Node, error)

MkdirAll creates a directory named path, along with any necessary parents, and returns the directory node and nil, or else returns an error. If path is already a directory, MkdirAll does nothing and returns the directory node and nil.

func (*Tree) RemoveNode

func (nt *Tree) RemoveNode(n *Node) error

RemoveNode removes this node from the server and from the NodeTree.

func (*Tree) Sync

func (nt *Tree) Sync() error

Sync syncs the tree with the server.

Jump to

Keyboard shortcuts

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