Commit ea030b67 authored by Henry's avatar Henry Committed by Juan Batiz-Benet

unixfs/io: added NewEmptyDirectory()

some golinting along the way
parent 0f1dc11a
...@@ -15,15 +15,22 @@ type directoryBuilder struct { ...@@ -15,15 +15,22 @@ type directoryBuilder struct {
dirnode *mdag.Node dirnode *mdag.Node
} }
// NewEmptyDirectory returns an empty merkledag Node with a folder Data chunk
func NewEmptyDirectory() *mdag.Node {
return &mdag.Node{Data: format.FolderPBData()}
}
// NewDirectory returns a directoryBuilder. It needs a DAGService to add the Children
func NewDirectory(dserv mdag.DAGService) *directoryBuilder { func NewDirectory(dserv mdag.DAGService) *directoryBuilder {
db := new(directoryBuilder) db := new(directoryBuilder)
db.dserv = dserv db.dserv = dserv
db.dirnode = new(mdag.Node) db.dirnode = NewEmptyDirectory()
db.dirnode.Data = format.FolderPBData()
return db return db
} }
// AddChild adds a (name, key)-pair to the root node.
func (d *directoryBuilder) AddChild(name string, k u.Key) error { func (d *directoryBuilder) AddChild(name string, k u.Key) error {
// TODO(cryptix): consolidate context managment
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute) ctx, cancel := context.WithTimeout(context.TODO(), time.Minute)
defer cancel() defer cancel()
...@@ -40,6 +47,7 @@ func (d *directoryBuilder) AddChild(name string, k u.Key) error { ...@@ -40,6 +47,7 @@ func (d *directoryBuilder) AddChild(name string, k u.Key) error {
return nil return nil
} }
// GetNode returns the root of this directoryBuilder
func (d *directoryBuilder) GetNode() *mdag.Node { func (d *directoryBuilder) GetNode() *mdag.Node {
return d.dirnode return d.dirnode
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment