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

Update dag put flags #252

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func (s *Shell) DagGet(ref string, out interface{}) error {
return s.Request("dag/get", ref).Exec(context.Background(), out)
}

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

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

return out.Cid.Target, s.
Request("dag/put").
Option("input-enc", cfg.InputEnc).
Option("format", cfg.Kind).
Option("input-codec", cfg.InputCodec).
Option("store-codec", cfg.StoreCodec).
Option("pin", cfg.Pin).
Option("hash", cfg.Hash).
Body(fileReader).
Expand Down
32 changes: 16 additions & 16 deletions options/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package options

// DagPutSettings is a set of DagPut options.
type DagPutSettings struct {
InputEnc string
Kind string
Pin string
Hash string
InputCodec string
StoreCodec string
Pin string
Hash string
}

// DagPutOption is a single DagPut option.
Expand All @@ -14,10 +14,10 @@ type DagPutOption func(opts *DagPutSettings) error
// DagPutOptions applies the given options to a DagPutSettings instance.
func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) {
options := &DagPutSettings{
InputEnc: "dag-json",
Kind: "dag-cbor",
Pin: "false",
Hash: "sha2-256",
InputCodec: "dag-json",
StoreCodec: "dag-cbor",
Pin: "false",
Hash: "sha2-256",
}

for _, opt := range opts {
Expand All @@ -42,20 +42,20 @@ func (dagOpts) Pin(pin string) DagPutOption {
}
}

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

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