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-dms3
Commits
2a15fe8e
Commit
2a15fe8e
authored
Nov 04, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(commands2/cat) readability
parent
c67e3771
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
11 deletions
+28
-11
core/commands2/cat.go
core/commands2/cat.go
+28
-11
No files found.
core/commands2/cat.go
View file @
2a15fe8e
package
commands
import
(
"errors"
"io"
cmds
"github.com/jbenet/go-ipfs/commands"
core
"github.com/jbenet/go-ipfs/core"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
)
...
...
@@ -14,26 +16,41 @@ var catCmd = &cmds.Command{
Help
:
"TODO"
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
node
:=
req
.
Context
()
.
Node
paths
:=
make
([]
string
,
0
,
len
(
req
.
Arguments
()))
readers
:=
make
([]
io
.
Reader
,
0
,
len
(
req
.
Arguments
()))
for
_
,
arg
:=
range
req
.
Arguments
()
{
path
:=
arg
.
(
string
)
dagnode
,
err
:=
node
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
read
,
err
:=
uio
.
NewDagReader
(
dagnode
,
node
.
DAG
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
path
,
ok
:=
arg
.
(
string
)
if
!
ok
{
res
.
SetError
(
errors
.
New
(
"cast error"
),
cmds
.
ErrNormal
)
return
}
paths
=
append
(
paths
,
path
)
}
readers
=
append
(
readers
,
read
)
readers
,
err
:=
cat
(
node
,
paths
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
reader
:=
io
.
MultiReader
(
readers
...
)
res
.
SetOutput
(
reader
)
},
}
func
cat
(
node
*
core
.
IpfsNode
,
paths
[]
string
)
([]
io
.
Reader
,
error
)
{
readers
:=
make
([]
io
.
Reader
,
0
,
len
(
paths
))
for
_
,
path
:=
range
paths
{
dagnode
,
err
:=
node
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
read
,
err
:=
uio
.
NewDagReader
(
dagnode
,
node
.
DAG
)
if
err
!=
nil
{
return
nil
,
err
}
readers
=
append
(
readers
,
read
)
}
return
readers
,
nil
}
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