package opts

import "github.com/multiformats/go-multihash/opts"

Package opts helps to write commands which may take multihash options.

Index

Variables

var (
	ErrMatch = errors.New("multihash checksums did not match")
)

package errors

var FlagValues = struct {
	Encodings  []string
	Algorithms []string
}{
	Encodings: []string{"raw", "hex", "base58", "base64"},
	Algorithms: func() []string {
		names := make([]string, 0, len(mh.Names))
		for n := range mh.Names {

			if strings.HasPrefix(n, "blake2") {
				switch n {
				case "blake2s-256":
				case "blake2b-128":
				case "blake2b-224":
				case "blake2b-256":
				case "blake2b-384":
				case "blake2b-512":
				default:
					continue
				}
			}
			names = append(names, n)
		}
		sort.Strings(names)
		return names
	}(),
}

FlagValues are the values the various option flags can take.

Functions

func Decode

func Decode(encoding, digest string) (mh.Multihash, error)

func Encode

func Encode(encoding string, hash mh.Multihash) (string, error)

Types

type Options

type Options struct {
	Encoding      string
	Algorithm     string
	AlgorithmCode uint64
	Length        int
	// contains filtered or unexported fields
}

Options is a struct used to parse cli flags.

func SetupFlags

func SetupFlags(f *flag.FlagSet) *Options

SetupFlags adds multihash related options to given flagset.

func (*Options) Check

func (o *Options) Check(r io.Reader, h1 mh.Multihash) error

Check reads all the data in r, calculates its multihash, and checks it matches h1

func (*Options) Multihash

func (o *Options) Multihash(r io.Reader) (mh.Multihash, error)

Multihash reads all the data in r and calculates its multihash.

func (*Options) Parse

func (o *Options) Parse(args []string) error

Parse parses the values of flags from given argument slice. It is equivalent to flags.Parse(args)

func (*Options) ParseError

func (o *Options) ParseError() error

ParseError checks the parsed options for errors.

Source Files

coding.go opts.go

Version
v0.2.3 (latest)
Published
Jun 12, 2023
Platform
linux/amd64
Imports
11 packages
Last checked
1 month ago

Tools for package owners.