Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
223ee4df
Commit
223ee4df
authored
Jan 10, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(core): move Add, Cat to core/io
parent
ddf14bee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
38 deletions
+72
-38
core/core.go
core/core.go
+0
-33
core/io/add.go
core/io/add.go
+35
-0
core/io/cat.go
core/io/cat.go
+30
-0
test/epictest/addcat_test.go
test/epictest/addcat_test.go
+3
-2
test/epictest/three_legged_cat_test.go
test/epictest/three_legged_cat_test.go
+4
-3
No files found.
core/core.go
View file @
223ee4df
...
...
@@ -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"
)
...
...
core/io/add.go
0 → 100644
View file @
223ee4df
package
core_io
// TODO rename package to something that doesn't conflict with io/ioutil.
// Pretty names are hard to find.
//
// Candidates:
//
// go-ipfs/core/unix
// go-ipfs/core/io
// go-ipfs/core/ioutil
// go-ipfs/core/coreio
// go-ipfs/core/coreunix
import
(
"io"
core
"github.com/jbenet/go-ipfs/core"
importer
"github.com/jbenet/go-ipfs/importer"
chunk
"github.com/jbenet/go-ipfs/importer/chunk"
u
"github.com/jbenet/go-ipfs/util"
)
func
Add
(
n
*
core
.
IpfsNode
,
r
io
.
Reader
)
(
u
.
Key
,
error
)
{
// TODO more attractive function signature importer.BuildDagFromReader
dagNode
,
err
:=
importer
.
BuildDagFromReader
(
r
,
n
.
DAG
,
nil
,
chunk
.
DefaultSplitter
,
)
if
err
!=
nil
{
return
""
,
err
}
return
dagNode
.
Key
()
}
core/io/cat.go
0 → 100644
View file @
223ee4df
package
core_io
// TODO rename package to something that doesn't conflict with io/ioutil.
// Pretty names are hard to find.
//
// Candidates:
//
// go-ipfs/core/unix
// go-ipfs/core/io
// go-ipfs/core/ioutil
// go-ipfs/core/coreio
// go-ipfs/core/coreunix
import
(
"io"
core
"github.com/jbenet/go-ipfs/core"
path
"github.com/jbenet/go-ipfs/path"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
u
"github.com/jbenet/go-ipfs/util"
)
func
Cat
(
n
*
core
.
IpfsNode
,
k
u
.
Key
)
(
io
.
Reader
,
error
)
{
dag
:=
n
.
DAG
dagNode
,
err
:=
(
&
path
.
Resolver
{
dag
})
.
ResolvePath
(
k
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
return
uio
.
NewDagReader
(
dagNode
,
dag
)
}
test/epictest/addcat_test.go
View file @
223ee4df
...
...
@@ -12,6 +12,7 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
random
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
"github.com/jbenet/go-ipfs/core"
core_io
"github.com/jbenet/go-ipfs/core/io"
mocknet
"github.com/jbenet/go-ipfs/p2p/net/mock"
"github.com/jbenet/go-ipfs/p2p/peer"
errors
"github.com/jbenet/go-ipfs/util/debugerror"
...
...
@@ -114,12 +115,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
catter
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
adder
.
Peerstore
.
PeerInfo
(
adder
.
Identity
)})
adder
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
catter
.
Peerstore
.
PeerInfo
(
catter
.
Identity
)})
keyAdded
,
err
:=
adder
.
Add
(
bytes
.
NewReader
(
data
))
keyAdded
,
err
:=
core_io
.
Add
(
adder
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
return
err
}
readerCatted
,
err
:=
c
atter
.
Cat
(
keyAdded
)
readerCatted
,
err
:=
c
ore_io
.
Cat
(
catter
,
keyAdded
)
if
err
!=
nil
{
return
err
}
...
...
test/epictest/three_legged_cat_test.go
View file @
223ee4df
...
...
@@ -7,7 +7,8 @@ import (
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/core"
core
"github.com/jbenet/go-ipfs/core"
core_io
"github.com/jbenet/go-ipfs/core/io"
mocknet
"github.com/jbenet/go-ipfs/p2p/net/mock"
"github.com/jbenet/go-ipfs/p2p/peer"
errors
"github.com/jbenet/go-ipfs/util/debugerror"
...
...
@@ -61,12 +62,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
adder
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
boostrapInfo
})
catter
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
boostrapInfo
})
keyAdded
,
err
:=
adder
.
Add
(
bytes
.
NewReader
(
data
))
keyAdded
,
err
:=
core_io
.
Add
(
adder
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
return
err
}
readerCatted
,
err
:=
c
atter
.
Cat
(
keyAdded
)
readerCatted
,
err
:=
c
ore_io
.
Cat
(
catter
,
keyAdded
)
if
err
!=
nil
{
return
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment