Skip to content

Commit 374df1a

Browse files
committed
shell: enable hash function selection when adding a file
1 parent 90b6ff4 commit 374df1a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

add.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os"
99
"path"
1010

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

1414
type object struct {
@@ -45,6 +45,14 @@ func RawLeaves(enabled bool) AddOpts {
4545
}
4646
}
4747

48+
// Hash allows for selecting the multihash type
49+
func Hash(hash string) AddOpts {
50+
return func(rb *RequestBuilder) error {
51+
rb.Option("hash", hash)
52+
return nil
53+
}
54+
}
55+
4856
func (s *Shell) Add(r io.Reader, options ...AddOpts) (string, error) {
4957
fr := files.NewReaderFile(r)
5058
slf := files.NewSliceDirectory([]files.DirEntry{files.FileEntry("", fr)})

shell_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func TestAdd(t *testing.T) {
2828
mhash, err := s.Add(bytes.NewBufferString("Hello IPFS Shell tests"))
2929
is.Nil(err)
3030
is.Equal(mhash, "QmUfZ9rAdhV5ioBzXKdUTh2ZNsz9bzbkaLVyQ8uc8pj21F")
31+
mhash, err = s.Add(bytes.NewBufferString("Hello IPFS Shell tests"), Hash("sha3-256"))
32+
is.Nil(err)
33+
is.Equal(mhash, "zb2wwqxjxosf8GKEZCwAWSFZ879XFNca3De5yAoh5b2axAffc")
3134
}
3235

3336
func TestRedirect(t *testing.T) {

0 commit comments

Comments
 (0)