Skip to content

Commit

Permalink
shell/fsnode: Add a high-level filesystem-node package
Browse files Browse the repository at this point in the history
Starting to use the core/... (low-level, all the knobs you need)
shell/... (high-level, handle the common case easily) disctinction
laid out in [1].

Creating a file node from a reader is hard to do right, because
there's a lot of filesystem metadata that we don't have access to
(access mode, ownership, etc.).  You can guess at those based on the
adding process's umask, effective user, etc., but figuring out what
you want guessed at or what you want set explicitly, or whether you
want wrapping metadata at all is complicated.  This function isn't
going to do any of that [2], it's just a high-level wrapper to create
a minimal file object with the default chunking, pinning, etc. all
taken care of in ways that will probably work for you ;).

[1]: ipfs#1158
[2]: ipfs#1136 (comment)
  • Loading branch information
wking committed Apr 29, 2015
1 parent c1a347d commit 2d048cb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
31 changes: 31 additions & 0 deletions shell/fsnode/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fsnode

import (
"io"

core "github.com/ipfs/go-ipfs/core"
importer "github.com/ipfs/go-ipfs/importer"
chunk "github.com/ipfs/go-ipfs/importer/chunk"
dag "github.com/ipfs/go-ipfs/merkledag"
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
)

var log = eventlog.Logger("shell/fsnode")

// Add builds a merkledag from a reader, pinning all objects to the
// local datastore. Returns the root node.
func AddFromReader(node *core.IpfsNode, reader io.Reader) (*dag.Node, error) {
fileNode, err := importer.BuildDagFromReader(
reader,
node.DAG,
node.Pinning.GetManual(),
chunk.DefaultSplitter,
)
if err != nil {
return nil, err
}
if err := node.Pinning.Flush(); err != nil {
return nil, err
}
return fileNode, nil
}
10 changes: 10 additions & 0 deletions shell/fsnode/fsnode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Package fsnode is a high-level interface for filesystem nodes.
Simple wrappers to:
* create file and directory nodes from paths and readers,
* extract file and directory nodes to your local filesytem, and
* print file contents to writers.
*/
package fsnode
8 changes: 8 additions & 0 deletions shell/shell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Package shell implements a high-level interface for common IPFS activity.
These wrappers around the low-level core interface make it easy to
accomplish common tasks with default settings. For steps where the
defaults aren't appropriate, you can use the core package directly.
*/
package shell

0 comments on commit 2d048cb

Please sign in to comment.