Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
0f234d76
提交
0f234d76
authored
8月 09, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dag: add option to specify hash
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
a1e923e2
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
63 行增加
和
38 行删除
+63
-38
dag.go
core/commands/dag/dag.go
+18
-1
unixfs_test.go
core/coreapi/unixfs_test.go
+3
-2
cbor.go
core/coredag/cbor.go
+32
-0
dagtransl.go
core/coredag/dagtransl.go
+7
-32
merkledag.go
merkledag/merkledag.go
+1
-1
package.json
package.json
+2
-2
没有找到文件。
core/commands/dag/dag.go
浏览文件 @
0f234d76
...
...
@@ -3,6 +3,7 @@ package dagcmd
import
(
"fmt"
"io"
"math"
"strings"
cmds
"github.com/ipfs/go-ipfs/commands"
...
...
@@ -11,6 +12,7 @@ import (
pin
"github.com/ipfs/go-ipfs/pin"
cid
"gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
mh
"gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
)
var
DagCmd
=
&
cmds
.
Command
{
...
...
@@ -48,6 +50,7 @@ into an object of the specified format.
cmds
.
StringOption
(
"format"
,
"f"
,
"Format that the object will be added as."
)
.
Default
(
"cbor"
),
cmds
.
StringOption
(
"input-enc"
,
"Format that the input object will be."
)
.
Default
(
"json"
),
cmds
.
BoolOption
(
"pin"
,
"Pin this object when adding."
)
.
Default
(
false
),
cmds
.
StringOption
(
"hash"
,
"Hash function to use"
)
.
Default
(
""
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
...
...
@@ -64,17 +67,31 @@ into an object of the specified format.
ienc
,
_
,
_
:=
req
.
Option
(
"input-enc"
)
.
String
()
format
,
_
,
_
:=
req
.
Option
(
"format"
)
.
String
()
hash
,
_
,
err
:=
req
.
Option
(
"hash"
)
.
String
()
dopin
,
_
,
err
:=
req
.
Option
(
"pin"
)
.
Bool
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
// mhType tells inputParser which hash should be used. MaxUint64 means 'use
// default hash' (sha256 for cbor, sha1 for git..)
mhType
:=
uint64
(
math
.
MaxUint64
)
if
hash
!=
""
{
var
ok
bool
mhType
,
ok
=
mh
.
Names
[
hash
]
if
!
ok
{
res
.
SetError
(
fmt
.
Errorf
(
"%s in not a valid multihash name"
,
hash
),
cmds
.
ErrNormal
)
return
}
}
if
dopin
{
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
}
nds
,
err
:=
coredag
.
ParseInputs
(
ienc
,
format
,
fi
)
nds
,
err
:=
coredag
.
ParseInputs
(
ienc
,
format
,
fi
,
mhType
,
-
1
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
...
...
core/coreapi/unixfs_test.go
浏览文件 @
0f234d76
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"io"
"math"
"strings"
"testing"
...
...
@@ -16,7 +17,7 @@ import (
config
"github.com/ipfs/go-ipfs/repo/config"
testutil
"github.com/ipfs/go-ipfs/thirdparty/testutil"
unixfs
"github.com/ipfs/go-ipfs/unixfs"
cbor
"gx/ipfs/Qm
XgUVPAxjMLZSyxx818YstJJAoRg3nyPWENmBLVzLtoax
/go-ipld-cbor"
cbor
"gx/ipfs/Qm
eebqVZeEXBqJ2B4urQWfdhwRRPm84ajnCo8x8pfwbsPM
/go-ipld-cbor"
)
// `echo -n 'hello, world!' | ipfs add`
...
...
@@ -277,7 +278,7 @@ func TestLsNonUnixfs(t *testing.T) {
t
.
Error
(
err
)
}
nd
,
err
:=
cbor
.
WrapObject
(
map
[
string
]
interface
{}{
"foo"
:
"bar"
})
nd
,
err
:=
cbor
.
WrapObject
(
map
[
string
]
interface
{}{
"foo"
:
"bar"
}
,
math
.
MaxUint64
,
-
1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
core/coredag/cbor.go
0 → 100644
浏览文件 @
0f234d76
package
coredag
import
(
"io"
"io/ioutil"
node
"gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
ipldcbor
"gx/ipfs/QmeebqVZeEXBqJ2B4urQWfdhwRRPm84ajnCo8x8pfwbsPM/go-ipld-cbor"
)
func
cborJSONParser
(
r
io
.
Reader
,
mhType
uint64
,
mhLen
int
)
([]
node
.
Node
,
error
)
{
nd
,
err
:=
ipldcbor
.
FromJson
(
r
,
mhType
,
mhLen
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
node
.
Node
{
nd
},
nil
}
func
cborRawParser
(
r
io
.
Reader
,
mhType
uint64
,
mhLen
int
)
([]
node
.
Node
,
error
)
{
data
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
nil
,
err
}
nd
,
err
:=
ipldcbor
.
Decode
(
data
,
mhType
,
mhLen
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
node
.
Node
{
nd
},
nil
}
core/coredag/dagtransl.go
浏览文件 @
0f234d76
...
...
@@ -3,14 +3,12 @@ package coredag
import
(
"fmt"
"io"
"io/ioutil"
ipldcbor
"gx/ipfs/QmXgUVPAxjMLZSyxx818YstJJAoRg3nyPWENmBLVzLtoax/go-ipld-cbor"
node
"gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
)
// DagParser is function used for parsing stream into Node
type
DagParser
func
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
type
DagParser
func
(
r
io
.
Reader
,
mhType
uint64
,
mhLen
int
)
([]
node
.
Node
,
error
)
// FormatParsers is used for mapping format descriptors to DagParsers
type
FormatParsers
map
[
string
]
DagParser
...
...
@@ -36,8 +34,8 @@ var defaultRawParsers = FormatParsers{
// ParseInputs uses DefaultInputEncParsers to parse io.Reader described by
// input encoding and format to an instance of ipld Node
func
ParseInputs
(
ienc
,
format
string
,
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
return
DefaultInputEncParsers
.
ParseInputs
(
ienc
,
format
,
r
)
func
ParseInputs
(
ienc
,
format
string
,
r
io
.
Reader
,
mhType
uint64
,
mhLen
int
)
([]
node
.
Node
,
error
)
{
return
DefaultInputEncParsers
.
ParseInputs
(
ienc
,
format
,
r
,
mhType
,
mhLen
)
}
// AddParser adds DagParser under give input encoding and format
...
...
@@ -53,39 +51,16 @@ func (iep InputEncParsers) AddParser(ienv, format string, f DagParser) {
// ParseInputs parses io.Reader described by input encoding and format to
// an instance of ipld Node
func
(
iep
InputEncParsers
)
ParseInputs
(
ienc
,
format
string
,
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
p
set
,
ok
:=
iep
[
ienc
]
func
(
iep
InputEncParsers
)
ParseInputs
(
ienc
,
format
string
,
r
io
.
Reader
,
mhType
uint64
,
mhLen
int
)
([]
node
.
Node
,
error
)
{
p
arsers
,
ok
:=
iep
[
ienc
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"no input parser for %q"
,
ienc
)
}
parser
,
ok
:=
p
set
[
format
]
parser
,
ok
:=
p
arsers
[
format
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"no parser for format %q using input type %q"
,
format
,
ienc
)
}
return
parser
(
r
)
}
func
cborJSONParser
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
nd
,
err
:=
ipldcbor
.
FromJson
(
r
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
node
.
Node
{
nd
},
nil
}
func
cborRawParser
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
data
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
nil
,
err
}
nd
,
err
:=
ipldcbor
.
Decode
(
data
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
node
.
Node
{
nd
},
nil
return
parser
(
r
,
mhType
,
mhLen
)
}
merkledag/merkledag.go
浏览文件 @
0f234d76
...
...
@@ -11,8 +11,8 @@ import (
cid
"gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
blocks
"gx/ipfs/QmVA4mafxbfH5aEvNz8fyoxC6J1xhAtw88B4GerPznSZBg/go-block-format"
ipldcbor
"gx/ipfs/QmXgUVPAxjMLZSyxx818YstJJAoRg3nyPWENmBLVzLtoax/go-ipld-cbor"
node
"gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
ipldcbor
"gx/ipfs/QmeebqVZeEXBqJ2B4urQWfdhwRRPm84ajnCo8x8pfwbsPM/go-ipld-cbor"
)
// TODO: We should move these registrations elsewhere. Really, most of the IPLD
...
...
package.json
浏览文件 @
0f234d76
...
...
@@ -261,9 +261,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
XgUVPAxjMLZSyxx818YstJJAoRg3nyPWENmBLVzLtoax
"
,
"hash"
:
"Qm
eebqVZeEXBqJ2B4urQWfdhwRRPm84ajnCo8x8pfwbsPM
"
,
"name"
:
"go-ipld-cbor"
,
"version"
:
"1.2.
7
"
"version"
:
"1.2.
8
"
},
{
"author"
:
"lgierth"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论