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
3b241486
Commit
3b241486
authored
Jul 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipfs cat
parent
62822145
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
1 deletion
+63
-1
cli/cat.go
cli/cat.go
+46
-0
cli/ipfs.go
cli/ipfs.go
+2
-1
core/core.go
core/core.go
+9
-0
merkledag/coding.go
merkledag/coding.go
+6
-0
No files found.
cli/cat.go
0 → 100644
View file @
3b241486
package
main
import
(
"github.com/gonuts/flag"
"github.com/jbenet/commander"
u
"github.com/jbenet/go-ipfs/util"
mh
"github.com/jbenet/go-multihash"
)
var
cmdIpfsCat
=
&
commander
.
Command
{
UsageLine
:
"cat"
,
Short
:
"Show ipfs object data."
,
Long
:
`ipfs cat <ipfs-path> - Show ipfs object data.
Retrieves the object named by <ipfs-path> and displays the Data
it contains.
`
,
Run
:
catCmd
,
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-cat"
,
flag
.
ExitOnError
),
}
func
catCmd
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
if
len
(
inp
)
<
1
{
u
.
POut
(
c
.
Long
)
return
nil
}
// for now only hashes, no path resolution
h
,
err
:=
mh
.
FromB58String
(
inp
[
0
])
if
err
!=
nil
{
return
err
}
n
,
err
:=
localNode
()
if
err
!=
nil
{
return
err
}
nd
,
err
:=
n
.
GetDagNode
(
u
.
Key
(
h
))
if
err
!=
nil
{
return
err
}
u
.
POut
(
"%s"
,
nd
.
Data
)
return
nil
}
cli/ipfs.go
View file @
3b241486
...
...
@@ -37,6 +37,7 @@ Use "ipfs help <command>" for more information about a command.
Run
:
ipfsCmd
,
Subcommands
:
[]
*
commander
.
Command
{
cmdIpfsAdd
,
cmdIpfsCat
,
cmdIpfsVersion
,
cmdIpfsCommands
,
},
...
...
@@ -52,7 +53,7 @@ func main() {
err
:=
CmdIpfs
.
Dispatch
(
os
.
Args
[
1
:
])
if
err
!=
nil
{
if
len
(
err
.
Error
())
>
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"
%v
\n
"
,
err
)
fmt
.
Fprintf
(
os
.
Stderr
,
"
ipfs %s: %v
\n
"
,
os
.
Args
[
1
]
,
err
)
}
os
.
Exit
(
1
)
}
...
...
core/core.go
View file @
3b241486
...
...
@@ -83,3 +83,12 @@ func (n *IpfsNode) AddDagNode(nd *merkledag.Node) (u.Key, error) {
return
n
.
Blocks
.
AddBlock
(
b
)
}
func
(
n
*
IpfsNode
)
GetDagNode
(
k
u
.
Key
)
(
*
merkledag
.
Node
,
error
)
{
b
,
err
:=
n
.
Blocks
.
GetBlock
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
return
merkledag
.
Decoded
(
b
.
Data
)
}
merkledag/coding.go
View file @
3b241486
...
...
@@ -71,3 +71,9 @@ func (n *Node) Encoded(force bool) ([]byte, error) {
return
n
.
encoded
,
nil
}
func
Decoded
(
encoded
[]
byte
)
(
*
Node
,
error
)
{
n
:=
&
Node
{}
err
:=
n
.
Unmarshal
(
encoded
)
return
n
,
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