Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/ipfs/go-ipfs-api/options"
"github.com/ipfs/go-ipfs-files"
files "github.com/ipfs/go-ipfs-files"
)

func (s *Shell) DagGet(ref string, out interface{}) error {
Expand Down Expand Up @@ -52,6 +52,7 @@ func (s *Shell) DagPutWithOpts(data interface{}, opts ...options.DagPutOption) (
Option("input-enc", cfg.InputEnc).
Option("format", cfg.Kind).
Option("pin", cfg.Pin).
Option("hash", cfg.Hash).
Body(fileReader).
Exec(context.Background(), &out)
}
10 changes: 10 additions & 0 deletions options/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type DagPutSettings struct {
InputEnc string
Kind string
Pin string
Hash string
}

// DagPutOption is a single DagPut option.
Expand All @@ -16,6 +17,7 @@ func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) {
InputEnc: "json",
Kind: "cbor",
Pin: "false",
Hash: "sha2-256",
}

for _, opt := range opts {
Expand Down Expand Up @@ -57,3 +59,11 @@ func (dagOpts) Kind(kind string) DagPutOption {
return nil
}
}

// Hash is an option for Dag.Put which specifies the hash function to use
func (dagOpts) Hash(hash string) DagPutOption {
return func(opts *DagPutSettings) error {
opts.Hash = hash
return nil
}
}