Skip to content

Commit 8e3700e

Browse files
author
postables
authored
Merge pull request #24 from RTradeLtd/ipfs/mh#select
Enable Multihash Selection
2 parents 90b6ff4 + 2e20472 commit 8e3700e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
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)})

log_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func Test_Logger(t *testing.T) {
99
ctx, cancel := context.WithCancel(context.Background())
1010
defer cancel()
11-
sh := NewLocalShell()
11+
sh := NewShell(shellUrl)
1212
logger, err := sh.GetLogs(ctx)
1313
if err != nil {
1414
t.Fatal(err)

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)