Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
coreapi unixfs: use fileAdder directly
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Oct 3, 2018
1 parent 713de02 commit 78136af
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
50 changes: 50 additions & 0 deletions options/unixfs.go
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
}
}
4 changes: 3 additions & 1 deletion unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"context"
"io"

options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"

ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
)

// UnixfsAPI is the basic interface to immutable files in IPFS
type UnixfsAPI interface {
// 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(context.Context, Path) (Reader, error)
Expand Down

0 comments on commit 78136af

Please sign in to comment.