Skip to content

Commit 96503ab

Browse files
authored
Merge pull request ipfs#175 from RTradeLtd/dag/hash
allow selecting hash function when using DagPutWithOpts
2 parents 740521c + 3362d23 commit 96503ab

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

dag.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"github.com/ipfs/go-ipfs-api/options"
11-
"github.com/ipfs/go-ipfs-files"
11+
files "github.com/ipfs/go-ipfs-files"
1212
)
1313

1414
func (s *Shell) DagGet(ref string, out interface{}) error {
@@ -52,6 +52,7 @@ func (s *Shell) DagPutWithOpts(data interface{}, opts ...options.DagPutOption) (
5252
Option("input-enc", cfg.InputEnc).
5353
Option("format", cfg.Kind).
5454
Option("pin", cfg.Pin).
55+
Option("hash", cfg.Hash).
5556
Body(fileReader).
5657
Exec(context.Background(), &out)
5758
}

options/dag.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type DagPutSettings struct {
55
InputEnc string
66
Kind string
77
Pin string
8+
Hash string
89
}
910

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

2123
for _, opt := range opts {
@@ -57,3 +59,11 @@ func (dagOpts) Kind(kind string) DagPutOption {
5759
return nil
5860
}
5961
}
62+
63+
// Hash is an option for Dag.Put which specifies the hash function to use
64+
func (dagOpts) Hash(hash string) DagPutOption {
65+
return func(opts *DagPutSettings) error {
66+
opts.Hash = hash
67+
return nil
68+
}
69+
}

0 commit comments

Comments
 (0)