-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shell/fsnode: Add a high-level filesystem-node package
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
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |