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
e42c9672
Commit
e42c9672
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option to only hash input
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
3a1c8d7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
core/builder.go
core/builder.go
+14
-3
core/commands/add.go
core/commands/add.go
+11
-0
No files found.
core/builder.go
View file @
e42c9672
...
...
@@ -23,6 +23,7 @@ type NodeBuilder struct {
peerhost
HostOption
repo
repo
.
Repo
built
bool
nilrepo
bool
}
func
NewNodeBuilder
()
*
NodeBuilder
{
...
...
@@ -33,7 +34,7 @@ func NewNodeBuilder() *NodeBuilder {
}
}
func
defaultRepo
()
(
repo
.
Repo
,
error
)
{
func
defaultRepo
(
dstore
ds
.
ThreadSafeDatastore
)
(
repo
.
Repo
,
error
)
{
c
:=
cfg
.
Config
{}
priv
,
pub
,
err
:=
ci
.
GenerateKeyPairWithReader
(
ci
.
RSA
,
1024
,
rand
.
Reader
)
if
err
!=
nil
{
...
...
@@ -56,7 +57,7 @@ func defaultRepo() (repo.Repo, error) {
c
.
Identity
.
PrivKey
=
base64
.
StdEncoding
.
EncodeToString
(
privkeyb
)
return
&
repo
.
Mock
{
D
:
ds
ync
.
MutexWrap
(
ds
.
NewMapDatas
tore
())
,
D
:
dstore
,
C
:
c
,
},
nil
}
...
...
@@ -86,13 +87,23 @@ func (nb *NodeBuilder) SetRepo(r repo.Repo) *NodeBuilder {
return
nb
}
func
(
nb
*
NodeBuilder
)
NilRepo
()
*
NodeBuilder
{
nb
.
nilrepo
=
true
return
nb
}
func
(
nb
*
NodeBuilder
)
Build
(
ctx
context
.
Context
)
(
*
IpfsNode
,
error
)
{
if
nb
.
built
{
return
nil
,
ErrAlreadyBuilt
}
nb
.
built
=
true
if
nb
.
repo
==
nil
{
r
,
err
:=
defaultRepo
()
var
d
ds
.
Datastore
d
=
ds
.
NewMapDatastore
()
if
nb
.
nilrepo
{
d
=
ds
.
NewNullDatastore
()
}
r
,
err
:=
defaultRepo
(
dsync
.
MutexWrap
(
d
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
core/commands/add.go
View file @
e42c9672
...
...
@@ -58,6 +58,7 @@ remains to be implemented.
cmds
.
BoolOption
(
progressOptionName
,
"p"
,
"Stream progress data"
),
cmds
.
BoolOption
(
wrapOptionName
,
"w"
,
"Wrap files with a directory object"
),
cmds
.
BoolOption
(
trickleOptionName
,
"t"
,
"Use trickle-dag format for dag generation"
),
cmds
.
BoolOption
(
"only-hash"
,
"n"
,
"Only chunk and hash the specified content, don't write to disk"
),
},
PreRun
:
func
(
req
cmds
.
Request
)
error
{
if
quiet
,
_
,
_
:=
req
.
Option
(
"quiet"
)
.
Bool
();
quiet
{
...
...
@@ -92,6 +93,16 @@ remains to be implemented.
progress
,
_
,
_
:=
req
.
Option
(
progressOptionName
)
.
Bool
()
trickle
,
_
,
_
:=
req
.
Option
(
trickleOptionName
)
.
Bool
()
wrap
,
_
,
_
:=
req
.
Option
(
wrapOptionName
)
.
Bool
()
hash
,
_
,
_
:=
req
.
Option
(
"only-hash"
)
.
Bool
()
if
hash
{
nilnode
,
err
:=
core
.
NewNodeBuilder
()
.
NilRepo
()
.
Build
(
n
.
Context
())
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
n
=
nilnode
}
outChan
:=
make
(
chan
interface
{},
8
)
res
.
SetOutput
((
<-
chan
interface
{})(
outChan
))
...
...
This diff is collapsed.
Click to expand it.
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