Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
a0f119fa
提交
a0f119fa
authored
10月 09, 2015
作者:
Juan Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1811 from ForrestWeston/master
Added an xml decoder, Fixes #1612
上级
9cfa23ee
6e243521
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
64 行增加
和
1 行删除
+64
-1
object.go
core/commands/object.go
+25
-1
brokenPut.xml
test/sharness/t0051-object-data/brokenPut.xml
+1
-0
testPut.xml
test/sharness/t0051-object-data/testPut.xml
+1
-0
t0051-object.sh
test/sharness/t0051-object.sh
+37
-0
没有找到文件。
core/commands/object.go
浏览文件 @
a0f119fa
...
...
@@ -3,6 +3,7 @@ package commands
import
(
"bytes"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io"
...
...
@@ -689,7 +690,7 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, err
// check that we have data in the Node to add
// otherwise we will add the empty object without raising an error
if
node
.
Data
==
""
&&
len
(
node
.
Links
)
==
0
{
if
NodeEmpty
(
node
)
{
return
nil
,
ErrEmptyNode
}
...
...
@@ -701,6 +702,24 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, err
case
objectEncodingProtobuf
:
dagnode
,
err
=
dag
.
Decoded
(
data
)
case
objectEncodingXML
:
node
:=
new
(
Node
)
err
=
xml
.
Unmarshal
(
data
,
node
)
if
err
!=
nil
{
return
nil
,
err
}
// check that we have data in the Node to add
// otherwise we will add the empty object without raising an error
if
NodeEmpty
(
node
)
{
return
nil
,
ErrEmptyNode
}
dagnode
,
err
=
deserializeNode
(
node
)
if
err
!=
nil
{
return
nil
,
err
}
default
:
return
nil
,
ErrUnknownObjectEnc
}
...
...
@@ -725,6 +744,7 @@ type objectEncoding string
const
(
objectEncodingJSON
objectEncoding
=
"json"
objectEncodingProtobuf
=
"protobuf"
objectEncodingXML
=
"xml"
)
func
getObjectEnc
(
o
interface
{})
objectEncoding
{
...
...
@@ -779,3 +799,7 @@ func deserializeNode(node *Node) (*dag.Node, error) {
return
dagnode
,
nil
}
func
NodeEmpty
(
node
*
Node
)
bool
{
return
(
node
.
Data
==
""
&&
len
(
node
.
Links
)
==
0
)
}
test/sharness/t0051-object-data/brokenPut.xml
0 → 100644
浏览文件 @
a0f119fa
<Noodles><Spaghetti>
This is not a valid dag object fail
</Spaghetti></Noodles>
test/sharness/t0051-object-data/testPut.xml
0 → 100644
浏览文件 @
a0f119fa
<Node><Data>
Test xml for sharness test
</Data></Node>
test/sharness/t0051-object.sh
浏览文件 @
a0f119fa
...
...
@@ -70,6 +70,43 @@ test_object_cmd() {
test_cmp expected_putOut actual_putOut
'
test_expect_success
"'ipfs object put file.xml' succeeds"
'
ipfs object put ../t0051-object-data/testPut.xml --inputenc=xml > actual_putOut
'
test_expect_success
"'ipfs object put file.xml' output looks good"
'
HASH="QmQzNKUHy4HyEUGkqKe3q3t796ffPLQXYCkHCcXUNT5JNK" &&
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.xml | ipfs object put --inputenc=xml > actual_putStdinOut
'
test_expect_success
"'ipfs object put broken.xml' should fail"
'
test_expect_code 1 ipfs object put ../t0051-object-data/brokenPut.xml --inputenc=xml 2>actual_putBrokenErr >actual_putBroken
'
test_expect_success
"'ipfs object put broken.hxml' output looks good"
'
touch expected_putBroken &&
printf "Error: no data or links in this node\n" > expected_putBrokenErr &&
test_cmp expected_putBroken actual_putBroken &&
test_cmp expected_putBrokenErr actual_putBrokenErr
'
test_expect_success
"'ipfs object get --enc=xml' succeeds"
'
ipfs object get --enc=xml $HASH >utf8_xml
'
test_expect_success
"'ipfs object put --inputenc=xml' succeeds"
'
ipfs object put --inputenc=xml <utf8_xml >actual
'
test_expect_failure
"'ipfs object put --inputenc=xml' output looks good"
'
echo "added $HASH" >expected &&
test_cmp expected actual
'
test_expect_success
"'ipfs object put file.pb' succeeds"
'
ipfs object put --inputenc=protobuf ../t0051-object-data/testPut.pb > actual_putOut
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论