@cryptotaxi247 / kubo / commits / 7d9ebdceb

coreapi unixfs: use fileAdder directly

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@78136afef00445d43c96ec7c66249b881dcf95ff This commit was moved from ipfs/boxo@60c358b08ca8bbb2773d19533ddd9b9864f3d360

Łukasz Magiera committed Sep 20, 2018 at 15:00 UTC 7d9ebdcebe6a0691a0921c167b2c513037b1cebc
2 files changed +53 -1
core/coreiface/options/unixfs.go new
+50
@@ -0,0 +1,50 @@
1 +package options
2 +
3 +import (
4 + mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
5 +)
6 +
7 +type UnixfsAddSettings struct {
8 + CidVersion int
9 + MhType uint64
10 +
11 + InlineLimit int
12 +}
13 +
14 +type UnixfsAddOption func(*UnixfsAddSettings) error
15 +
16 +func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, error) {
17 + options := &UnixfsAddSettings{
18 + CidVersion: -1,
19 + MhType: mh.SHA2_256,
20 +
21 + InlineLimit: 0,
22 + }
23 +
24 + for _, opt := range opts {
25 + err := opt(options)
26 + if err != nil {
27 + return nil, err
28 + }
29 + }
30 +
31 + return options, nil
32 +}
33 +
34 +type unixfsOpts struct{}
35 +
36 +var Unixfs unixfsOpts
37 +
38 +func (unixfsOpts) CidVersion(version int) UnixfsAddOption {
39 + return func(settings *UnixfsAddSettings) error {
40 + settings.CidVersion = version
41 + return nil
42 + }
43 +}
44 +
45 +func (unixfsOpts) Hash(mhtype uint64) UnixfsAddOption {
46 + return func(settings *UnixfsAddSettings) error {
47 + settings.MhType = mhtype
48 + return nil
49 + }
50 +}
core/coreiface/unixfs.go
+3 -1
@@ -4,13 +4,15 @@ import (
4 "context"
5 "io"
6
7 + options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8 +
9 ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
10 )
11
12 // UnixfsAPI is the basic interface to immutable files in IPFS
13 type UnixfsAPI interface {
14 // Add imports the data from the reader into merkledag file
13 - Add(context.Context, io.Reader) (ResolvedPath, error)
15 + Add(context.Context, io.ReadCloser, ...options.UnixfsAddOption) (ResolvedPath, error)
16
17 // Cat returns a reader for the file
18 Cat(context.Context, Path) (Reader, error)