diff --git a/dag.go b/dag.go index edfcbacdb..cf5886f07 100644 --- a/dag.go +++ b/dag.go @@ -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 { @@ -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) } diff --git a/options/dag.go b/options/dag.go index a7ecfce2c..6181f5a06 100644 --- a/options/dag.go +++ b/options/dag.go @@ -5,6 +5,7 @@ type DagPutSettings struct { InputEnc string Kind string Pin string + Hash string } // DagPutOption is a single DagPut option. @@ -16,6 +17,7 @@ func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) { InputEnc: "json", Kind: "cbor", Pin: "false", + Hash: "sha2-256", } for _, opt := range opts { @@ -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 + } +}