Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 39cfea2

Browse files
authored
Merge pull request #252 from ipfs/feat/update-dag-put-flags
Update dag put flags
2 parents ebc9d77 + 60a7f58 commit 39cfea2

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

dag.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func (s *Shell) DagGet(ref string, out interface{}) error {
1515
return s.Request("dag/get", ref).Exec(context.Background(), out)
1616
}
1717

18-
func (s *Shell) DagPut(data interface{}, ienc, kind string) (string, error) {
19-
return s.DagPutWithOpts(data, options.Dag.InputEnc(ienc), options.Dag.Kind(kind))
18+
func (s *Shell) DagPut(data interface{}, inputCodec, storeCodec string) (string, error) {
19+
return s.DagPutWithOpts(data, options.Dag.InputCodec(inputCodec), options.Dag.StoreCodec(storeCodec))
2020
}
2121

2222
func (s *Shell) DagPutWithOpts(data interface{}, opts ...options.DagPutOption) (string, error) {
@@ -49,8 +49,8 @@ func (s *Shell) DagPutWithOpts(data interface{}, opts ...options.DagPutOption) (
4949

5050
return out.Cid.Target, s.
5151
Request("dag/put").
52-
Option("input-enc", cfg.InputEnc).
53-
Option("format", cfg.Kind).
52+
Option("input-codec", cfg.InputCodec).
53+
Option("store-codec", cfg.StoreCodec).
5454
Option("pin", cfg.Pin).
5555
Option("hash", cfg.Hash).
5656
Body(fileReader).

options/dag.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package options
22

33
// DagPutSettings is a set of DagPut options.
44
type DagPutSettings struct {
5-
InputEnc string
6-
Kind string
7-
Pin string
8-
Hash string
5+
InputCodec string
6+
StoreCodec string
7+
Pin string
8+
Hash string
99
}
1010

1111
// DagPutOption is a single DagPut option.
@@ -14,10 +14,10 @@ type DagPutOption func(opts *DagPutSettings) error
1414
// DagPutOptions applies the given options to a DagPutSettings instance.
1515
func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) {
1616
options := &DagPutSettings{
17-
InputEnc: "dag-json",
18-
Kind: "dag-cbor",
19-
Pin: "false",
20-
Hash: "sha2-256",
17+
InputCodec: "dag-json",
18+
StoreCodec: "dag-cbor",
19+
Pin: "false",
20+
Hash: "sha2-256",
2121
}
2222

2323
for _, opt := range opts {
@@ -42,20 +42,20 @@ func (dagOpts) Pin(pin string) DagPutOption {
4242
}
4343
}
4444

45-
// InputEnc is an option for Dag.Put which specifies the input encoding of the
46-
// data. Default is "json", most formats/codecs support "raw".
47-
func (dagOpts) InputEnc(enc string) DagPutOption {
45+
// InputCodec is an option for Dag.Put which specifies the input encoding of the
46+
// data. Default is "dag-json".
47+
func (dagOpts) InputCodec(codec string) DagPutOption {
4848
return func(opts *DagPutSettings) error {
49-
opts.InputEnc = enc
49+
opts.InputCodec = codec
5050
return nil
5151
}
5252
}
5353

54-
// Kind is an option for Dag.Put which specifies the format that the dag
55-
// will be added as. Default is "cbor".
56-
func (dagOpts) Kind(kind string) DagPutOption {
54+
// StoreCodec is an option for Dag.Put which specifies the codec that the stored
55+
// object will be encoded with. Default is "dag-cbor".
56+
func (dagOpts) StoreCodec(codec string) DagPutOption {
5757
return func(opts *DagPutSettings) error {
58-
opts.Kind = kind
58+
opts.StoreCodec = codec
5959
return nil
6060
}
6161
}

0 commit comments

Comments
 (0)