This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Henrique Dias <[email protected]>
- Loading branch information
1 parent
82a4237
commit c356d0d
Showing
8 changed files
with
304 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,5 @@ | ||
package options | ||
|
||
// DagPutSettings is a set of DagPut options. | ||
type DagPutSettings struct { | ||
InputCodec string | ||
StoreCodec string | ||
Pin string | ||
Hash string | ||
} | ||
|
||
// DagPutOption is a single DagPut option. | ||
type DagPutOption func(opts *DagPutSettings) error | ||
|
||
// DagPutOptions applies the given options to a DagPutSettings instance. | ||
func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) { | ||
options := &DagPutSettings{ | ||
InputCodec: "dag-json", | ||
StoreCodec: "dag-cbor", | ||
Pin: "false", | ||
Hash: "sha2-256", | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return options, nil | ||
} | ||
|
||
type dagOpts struct{} | ||
|
||
var Dag dagOpts | ||
|
||
// Pin is an option for Dag.Put which specifies whether to pin the added | ||
// dags. Default is "false". | ||
func (dagOpts) Pin(pin string) DagPutOption { | ||
return func(opts *DagPutSettings) error { | ||
opts.Pin = pin | ||
return nil | ||
} | ||
} | ||
|
||
// 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.InputCodec = codec | ||
return nil | ||
} | ||
} | ||
|
||
// 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.StoreCodec = codec | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package options | ||
|
||
// DagImportSettings is a set of DagImport options. | ||
type DagImportSettings struct { | ||
PinRoots bool | ||
Silent bool | ||
Stats bool | ||
AllowBigBlock bool | ||
} | ||
|
||
// DagImportOption is a single DagImport option. | ||
type DagImportOption func(opts *DagImportSettings) error | ||
|
||
// DagImportOptions applies the given options to a DagImportSettings instance. | ||
func DagImportOptions(opts ...DagImportOption) (*DagImportSettings, error) { | ||
options := &DagImportSettings{ | ||
PinRoots: true, | ||
Silent: false, | ||
Stats: false, | ||
AllowBigBlock: false, | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return options, nil | ||
} | ||
|
||
// PinRoots is an option for Dag.Import which specifies whether to | ||
// pin the optional roots listed in the .car headers after importing. | ||
// Default is true. | ||
func (dagOpts) PinRoots(pinRoots bool) DagImportOption { | ||
return func(opts *DagImportSettings) error { | ||
opts.PinRoots = pinRoots | ||
return nil | ||
} | ||
} | ||
|
||
// Silent is an option for Dag.Import which specifies whether to | ||
// return any output or not. | ||
// Default is false. | ||
func (dagOpts) Silent(silent bool) DagImportOption { | ||
return func(opts *DagImportSettings) error { | ||
opts.Silent = silent | ||
return nil | ||
} | ||
} | ||
|
||
// Stats is an option for Dag.Import which specifies whether to | ||
// return stats about the import operation. | ||
// Default is false. | ||
func (dagOpts) Stats(stats bool) DagImportOption { | ||
return func(opts *DagImportSettings) error { | ||
opts.Stats = stats | ||
return nil | ||
} | ||
} | ||
|
||
// AllowBigBlock is an option for Dag.Import which disables block size check | ||
// and allow creation of blocks bigger than 1MiB. | ||
// WARNING: such blocks won't be transferable over the standard bitswap. | ||
// Default is false. | ||
func (dagOpts) AllowBigBlock(allowBigBlock bool) DagImportOption { | ||
return func(opts *DagImportSettings) error { | ||
opts.AllowBigBlock = allowBigBlock | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package options | ||
|
||
// DagPutSettings is a set of Dag options. | ||
type DagPutSettings struct { | ||
InputCodec string | ||
StoreCodec string | ||
Pin string | ||
Hash string | ||
} | ||
|
||
// DagPutOption is a single Dag option. | ||
type DagPutOption func(opts *DagPutSettings) error | ||
|
||
// DagPutOptions applies the given options to a DagPutSettings instance. | ||
func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) { | ||
options := &DagPutSettings{ | ||
InputCodec: "dag-json", | ||
StoreCodec: "dag-cbor", | ||
Pin: "false", | ||
Hash: "sha2-256", | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return options, nil | ||
} | ||
|
||
// Pin is an option for Dag.Put which specifies whether to pin the added | ||
// dags. Default is "false". | ||
func (dagOpts) Pin(pin string) DagPutOption { | ||
return func(opts *DagPutSettings) error { | ||
opts.Pin = pin | ||
return nil | ||
} | ||
} | ||
|
||
// 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.InputCodec = codec | ||
return nil | ||
} | ||
} | ||
|
||
// 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.StoreCodec = codec | ||
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 | ||
} | ||
} |
Oops, something went wrong.