This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coreapi unixfs: use fileAdder directly
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package options | ||
|
||
import ( | ||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash" | ||
) | ||
|
||
type UnixfsAddSettings struct { | ||
CidVersion int | ||
MhType uint64 | ||
|
||
InlineLimit int | ||
} | ||
|
||
type UnixfsAddOption func(*UnixfsAddSettings) error | ||
|
||
func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, error) { | ||
options := &UnixfsAddSettings{ | ||
CidVersion: -1, | ||
MhType: mh.SHA2_256, | ||
|
||
InlineLimit: 0, | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return options, nil | ||
} | ||
|
||
type unixfsOpts struct{} | ||
|
||
var Unixfs unixfsOpts | ||
|
||
func (unixfsOpts) CidVersion(version int) UnixfsAddOption { | ||
return func(settings *UnixfsAddSettings) error { | ||
settings.CidVersion = version | ||
return nil | ||
} | ||
} | ||
|
||
func (unixfsOpts) Hash(mhtype uint64) UnixfsAddOption { | ||
return func(settings *UnixfsAddSettings) error { | ||
settings.MhType = mhtype | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters