mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
refactor(core): move Add, Cat to core/io
This commit is contained in:
33
core/core.go
33
core/core.go
@ -2,7 +2,6 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
|
||||
@ -19,8 +18,6 @@ import (
|
||||
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
|
||||
offline "github.com/jbenet/go-ipfs/exchange/offline"
|
||||
mount "github.com/jbenet/go-ipfs/fuse/mount"
|
||||
importer "github.com/jbenet/go-ipfs/importer"
|
||||
chunk "github.com/jbenet/go-ipfs/importer/chunk"
|
||||
merkledag "github.com/jbenet/go-ipfs/merkledag"
|
||||
namesys "github.com/jbenet/go-ipfs/namesys"
|
||||
ic "github.com/jbenet/go-ipfs/p2p/crypto"
|
||||
@ -32,8 +29,6 @@ import (
|
||||
pin "github.com/jbenet/go-ipfs/pin"
|
||||
routing "github.com/jbenet/go-ipfs/routing"
|
||||
dht "github.com/jbenet/go-ipfs/routing/dht"
|
||||
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
ds2 "github.com/jbenet/go-ipfs/util/datastore2"
|
||||
debugerror "github.com/jbenet/go-ipfs/util/debugerror"
|
||||
eventlog "github.com/jbenet/go-ipfs/util/eventlog"
|
||||
@ -281,34 +276,6 @@ func (n *IpfsNode) Bootstrap(ctx context.Context, peers []peer.PeerInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO we may not want to add these methods to the core. Maybe they should be
|
||||
// defined as free functions in another package that use public fields on the
|
||||
// node.
|
||||
//
|
||||
// e.g. reader, err := unix.Cat(node)
|
||||
|
||||
func (n *IpfsNode) Cat(k u.Key) (io.Reader, error) {
|
||||
catterdag := n.DAG
|
||||
nodeCatted, err := (&path.Resolver{catterdag}).ResolvePath(k.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uio.NewDagReader(nodeCatted, catterdag)
|
||||
}
|
||||
|
||||
func (n *IpfsNode) Add(r io.Reader) (u.Key, error) {
|
||||
nodeAdded, err := importer.BuildDagFromReader(
|
||||
r,
|
||||
n.DAG,
|
||||
nil,
|
||||
chunk.DefaultSplitter,
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return nodeAdded.Key()
|
||||
}
|
||||
|
||||
func (n *IpfsNode) loadID() error {
|
||||
if n.Identity != "" {
|
||||
return debugerror.New("identity already loaded")
|
||||
|
Reference in New Issue
Block a user