-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Replace coreunix.Add with shell/fsnode's AddFromReader #1136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b42e7dd
c6bf6a8
9deaa04
1d404a7
f91e326
03458dc
6388c70
20ff6a7
93df40d
c8f7b39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,12 @@ import ( | |
|
||
var log = eventlog.Logger("coreunix") | ||
|
||
// Add builds a merkledag from the a reader, pinning all objects to the local | ||
// datastore. Returns a key representing the root node. | ||
// DEPRECATED: Add builds a merkledag from the a reader, pinning all | ||
// objects to the local datastore. Returns a key representing the root | ||
// node. | ||
// | ||
// This function is deprecated and will be removed in 0.4.0. You | ||
// should use shell/unixfs's AddFromReader instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove this comment. regardless of the future, today, this is not deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Fri, May 01, 2015 at 04:58:19AM -0700, Juan Batiz-Benet wrote:
Most of my later commits in this branch (and some of the earlier ones)
Once we've resolved strings vs []bytes 1, we can merge:
And then once we've decided to deprecate coreunix.Add we can merge:
Until we want to deprecate coreunix.Add, the shell/unixfs stuff is If that sounds reasonable, I'm fine with you just merging up to the |
||
func Add(n *core.IpfsNode, r io.Reader) (string, error) { | ||
// TODO more attractive function signature importer.BuildDagFromReader | ||
dagNode, err := importer.BuildDagFromReader( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# `core/coreunix`'s `Add` → `shell/unixfs`'s `AddFromReader` | ||
|
||
We've added an `AddFromReader` function to `shell/unixfs`. The old | ||
`Add` from `core/coreunix` is deprecated and will be removed in | ||
version 0.4.0. To update your existing code, change usage like: | ||
|
||
keyString, err := coreunix.Add(ipfsNode, reader) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
to | ||
|
||
fileNode, err := unixfs.AddFromReader(ipfsNode, reader) | ||
if err != nil { | ||
return err | ||
} | ||
key, err := fileNode.Key() | ||
if err != nil { | ||
return err | ||
} | ||
keyString := key.String() | ||
|
||
That's a bit more verbose if all you want is the stringified key, but | ||
returning a `dag.Node` makes it easier to perform other operations | ||
like adding the file node to a directory node. |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package unixfs | ||
|
||
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" | ||
) | ||
|
||
// 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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Package unixfs 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 unixfs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why not using the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, Apr 29, 2015 at 01:27:43PM -0700, Juan Batiz-Benet wrote:
Because I wanted AddNodeLink. Cycling from node → key string → node →
AddNodeLink (which is what AddChild does 1) seemed wasteful and
awkward (see note in 0ce5784, cmd/ipfs/init: Replace coreunix.Add
with importer.BuildDagFromReader, 2015-04-24).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or define a method
dirb.AddNodeLink(node)
.