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
276f471c
Commit
276f471c
authored
Mar 07, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #882 from jbenet/ipfsObject
Ipfs object put from stdin
parents
5db973a2
2a0cd6d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
12 deletions
+116
-12
core/commands/object.go
core/commands/object.go
+21
-12
test/sharness/t0051-object-data/expected_getOut
test/sharness/t0051-object-data/expected_getOut
+4
-0
test/sharness/t0051-object-data/testPut.json
test/sharness/t0051-object-data/testPut.json
+3
-0
test/sharness/t0051-object-data/testPut.pb
test/sharness/t0051-object-data/testPut.pb
+2
-0
test/sharness/t0051-object.sh
test/sharness/t0051-object.sh
+86
-0
No files found.
core/commands/object.go
View file @
276f471c
...
...
@@ -35,11 +35,11 @@ var ObjectCmd = &cmds.Command{
'ipfs object' is a plumbing command used to manipulate DAG objects
directly.`
,
Synopsis
:
`
ipfs object get <key>
- Get the DAG node named by <key>
ipfs object put <data>
<encoding>
- Stores input, outputs its key
ipfs object data <key>
- Outputs raw bytes in an object
ipfs object links <key>
- Outputs links pointed to by object
ipfs object stat <key>
- Outputs statistics of object
ipfs object get <key> - Get the DAG node named by <key>
ipfs object put <data> - Stores input, outputs its key
ipfs object data <key> - Outputs raw bytes in an object
ipfs object links <key> - Outputs links pointed to by object
ipfs object stat <key> - Outputs statistics of object
`
,
},
...
...
@@ -274,16 +274,18 @@ It reads from stdin, and the output is a base58 encoded multihash.
'ipfs object put' is a plumbing command for storing DAG nodes.
It reads from stdin, and the output is a base58 encoded multihash.
Data should be in the format specified by
<encoding>
.
<encoding>
may be one of the following:
Data should be in the format specified by
the --inputenc flag
.
--inputenc
may be one of the following:
* "protobuf"
* "json"
* "json"
(default)
`
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
FileArg
(
"data"
,
true
,
false
,
"Data to be stored as a DAG object"
),
cmds
.
StringArg
(
"encoding"
,
true
,
false
,
"Encoding type of <data>, either
\"
protobuf
\"
or
\"
json
\"
"
),
cmds
.
FileArg
(
"data"
,
true
,
false
,
"Data to be stored as a DAG object"
)
.
EnableStdin
(),
},
Options
:
[]
cmds
.
Option
{
cmds
.
StringOption
(
"inputenc"
,
"Encoding type of input data, either
\"
protobuf
\"
or
\"
json
\"
"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
Context
()
.
GetNode
()
...
...
@@ -298,9 +300,16 @@ Data should be in the format specified by <encoding>.
return
}
encoding
:=
req
.
Arguments
()[
0
]
inputenc
,
found
,
err
:=
req
.
Option
(
"inputenc"
)
.
String
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
found
{
inputenc
=
"json"
}
output
,
err
:=
objectPut
(
n
,
input
,
encoding
)
output
,
err
:=
objectPut
(
n
,
input
,
inputenc
)
if
err
!=
nil
{
errType
:=
cmds
.
ErrNormal
if
err
==
ErrUnknownObjectEnc
{
...
...
test/sharness/t0051-object-data/expected_getOut
0 → 100644
View file @
276f471c
{
"Links": [],
"Data": "\u0008\u0002\u0012\nHello Mars\u0018\n"
}
\ No newline at end of file
test/sharness/t0051-object-data/testPut.json
0 → 100644
View file @
276f471c
{
"Data"
:
"test json for sharness test"
}
test/sharness/t0051-object-data/testPut.pb
0 → 100644
View file @
276f471c
test json for sharness test
\ No newline at end of file
test/sharness/t0051-object.sh
0 → 100755
View file @
276f471c
#!/bin/sh
#
# Copyright (c) 2015 Henry Bubert
# MIT Licensed; see the LICENSE file in this repository.
#
test_description
=
"Test object command"
.
lib/test-lib.sh
test_init_ipfs
test_expect_success
"'ipfs add testData' succeeds"
'
printf "Hello Mars" >expected_in &&
ipfs add expected_in >actual_Addout
'
test_expect_success
"'ipfs add testData' output looks good"
'
HASH="QmWkHFpYBZ9mpPRreRbMhhYWXfUhBAue3JkbbpFqwowSRb" &&
echo "added $HASH expected_in" >expected_Addout &&
test_cmp expected_Addout actual_Addout
'
test_expect_success
"'ipfs object get' succeeds"
'
ipfs object get $HASH >actual_getOut
'
test_expect_success
"'ipfs object get' output looks good"
'
test_cmp ../t0051-object-data/expected_getOut actual_getOut
'
test_expect_success
"'ipfs object stat' succeeds"
'
ipfs object stat $HASH >actual_stat
'
test_expect_success
"'ipfs object get' output looks good"
'
echo "NumLinks: 0" >> expected_stat &&
echo "BlockSize: 18" >> expected_stat &&
echo "LinksSize: 2" >> expected_stat &&
echo "DataSize: 16" >> expected_stat &&
echo "CumulativeSize: 18" >> expected_stat &&
test_cmp expected_stat actual_stat
'
test_expect_success
"'ipfs object put file.json' succeeds"
'
ipfs object put ../t0051-object-data/testPut.json > actual_putOut
'
test_expect_success
"'ipfs object put file.json' output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putOut &&
test_cmp expected_putOut actual_putOut
'
test_expect_success
"'ipfs object put file.pb' succeeds"
'
ipfs object put --inputenc=protobuf ../t0051-object-data/testPut.pb > actual_putOut
'
test_expect_success
"'ipfs object put file.pb' output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putOut &&
test_cmp expected_putOut actual_putOut
'
test_expect_success
"'ipfs object put' from stdin succeeds"
'
cat ../t0051-object-data/testPut.json | ipfs object put > actual_putStdinOut
'
test_expect_success
"'ipfs object put' from stdin output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putStdinOut &&
test_cmp expected_putStdinOut actual_putStdinOut
'
test_expect_success
"'ipfs object put' from stdin (pb) succeeds"
'
cat ../t0051-object-data/testPut.pb | ipfs object put --inputenc=protobuf > actual_putPbStdinOut
'
test_expect_success
"'ipfs object put' from stdin (pb) output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putStdinOut &&
test_cmp expected_putStdinOut actual_putPbStdinOut
'
test_done
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