Commit 78136afe authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi unixfs: use fileAdder directly

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 713de024
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
}
}
...@@ -4,13 +4,15 @@ import ( ...@@ -4,13 +4,15 @@ import (
"context" "context"
"io" "io"
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format" ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
) )
// UnixfsAPI is the basic interface to immutable files in IPFS // UnixfsAPI is the basic interface to immutable files in IPFS
type UnixfsAPI interface { type UnixfsAPI interface {
// Add imports the data from the reader into merkledag file // Add imports the data from the reader into merkledag file
Add(context.Context, io.Reader) (ResolvedPath, error) Add(context.Context, io.ReadCloser, ...options.UnixfsAddOption) (ResolvedPath, error)
// Cat returns a reader for the file // Cat returns a reader for the file
Cat(context.Context, Path) (Reader, error) Cat(context.Context, Path) (Reader, error)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment