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
interface-go-dms3-core
Commits
e62f2650
Commit
e62f2650
authored
Sep 20, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi unixfs: cleanup options
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
8521907e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
3 deletions
+38
-3
options/unixfs.go
options/unixfs.go
+38
-3
No files found.
options/unixfs.go
View file @
e62f2650
package
options
import
(
"errors"
"fmt"
cid
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
dag
"gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
)
type
Layout
int
...
...
@@ -29,7 +34,7 @@ type UnixfsAddSettings struct {
type
UnixfsAddOption
func
(
*
UnixfsAddSettings
)
error
func
UnixfsAddOptions
(
opts
...
UnixfsAddOption
)
(
*
UnixfsAddSettings
,
error
)
{
func
UnixfsAddOptions
(
opts
...
UnixfsAddOption
)
(
*
UnixfsAddSettings
,
cid
.
Prefix
,
error
)
{
options
:=
&
UnixfsAddSettings
{
CidVersion
:
-
1
,
MhType
:
mh
.
SHA2_256
,
...
...
@@ -49,11 +54,41 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, error) {
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
return
nil
,
cid
.
Prefix
{},
err
}
}
// (hash != "sha2-256") -> CIDv1
if
options
.
MhType
!=
mh
.
SHA2_256
{
switch
options
.
CidVersion
{
case
0
:
return
nil
,
cid
.
Prefix
{},
errors
.
New
(
"CIDv0 only supports sha2-256"
)
case
1
,
-
1
:
options
.
CidVersion
=
1
default
:
return
nil
,
cid
.
Prefix
{},
fmt
.
Errorf
(
"unknown CID version: %d"
,
options
.
CidVersion
)
}
}
else
{
if
options
.
CidVersion
<
0
{
// Default to CIDv0
options
.
CidVersion
=
0
}
}
return
options
,
nil
// cidV1 -> raw blocks (by default)
if
options
.
CidVersion
>
0
&&
!
options
.
RawLeavesSet
{
options
.
RawLeaves
=
true
}
prefix
,
err
:=
dag
.
PrefixForCidVersion
(
options
.
CidVersion
)
if
err
!=
nil
{
return
nil
,
cid
.
Prefix
{},
err
}
prefix
.
MhType
=
options
.
MhType
prefix
.
MhLength
=
-
1
return
options
,
prefix
,
nil
}
type
unixfsOpts
struct
{}
...
...
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