go-multibase: github.com/multiformats/go-multibase Index | Files | Directories

package multibase

import "github.com/multiformats/go-multibase"


Package Files

base16.go base2.go base32.go encoder.go multibase.go


const (
    Identity          = 0x00
    Base2             = '0'
    Base8             = '7'
    Base10            = '9'
    Base16            = 'f'
    Base16Upper       = 'F'
    Base32            = 'b'
    Base32Upper       = 'B'
    Base32pad         = 'c'
    Base32padUpper    = 'C'
    Base32hex         = 'v'
    Base32hexUpper    = 'V'
    Base32hexPad      = 't'
    Base32hexPadUpper = 'T'
    Base36            = 'k'
    Base36Upper       = 'K'
    Base58BTC         = 'z'
    Base58Flickr      = 'Z'
    Base64            = 'm'
    Base64url         = 'u'
    Base64pad         = 'M'
    Base64urlPad      = 'U'

These are the encodings specified in the standard, not are all supported yet


var EncodingToStr = map[Encoding]string{
    0x00: "identity",
    '0':  "base2",
    'f':  "base16",
    'F':  "base16upper",
    'b':  "base32",
    'B':  "base32upper",
    'c':  "base32pad",
    'C':  "base32padupper",
    'v':  "base32hex",
    'V':  "base32hexupper",
    't':  "base32hexpad",
    'T':  "base32hexpadupper",
    'k':  "base36",
    'K':  "base36upper",
    'z':  "base58btc",
    'Z':  "base58flickr",
    'm':  "base64",
    'u':  "base64url",
    'M':  "base64pad",
    'U':  "base64urlpad",

EncodingToStr is a map of the supported encoding, unsupported encoding specified in standard are left out

var Encodings = map[string]Encoding{}
var ErrUnsupportedEncoding = fmt.Errorf("selected encoding not supported")

ErrUnsupportedEncoding is returned when the selected encoding is not known or implemented.

func Encode Uses

func Encode(base Encoding, data []byte) (string, error)

Encode encodes a given byte slice with the selected encoding and returns a multibase string (<encoding><base-encoded-string>). It will return an error if the selected base is not known.

type Encoder Uses

type Encoder struct {
    // contains filtered or unexported fields

Encoder is a multibase encoding that is verified to be supported and supports an Encode method that does not return an error

func EncoderByName Uses

func EncoderByName(str string) (Encoder, error)

EncoderByName creates an encoder from a string, the string can either be the multibase name or single character multibase prefix

func MustNewEncoder Uses

func MustNewEncoder(base Encoding) Encoder

MustNewEncoder is like NewEncoder but will panic if the encoding is invalid.

func NewEncoder Uses

func NewEncoder(base Encoding) (Encoder, error)

NewEncoder create a new Encoder from an Encoding

func (Encoder) Encode Uses

func (p Encoder) Encode(data []byte) string

Encode encodes the multibase using the given Encoder.

func (Encoder) Encoding Uses

func (p Encoder) Encoding() Encoding

type Encoding Uses

type Encoding int

Encoding identifies the type of base-encoding that a multibase is carrying.

func Decode Uses

func Decode(data string) (Encoding, []byte, error)

Decode takes a multibase string and decodes into a bytes buffer. It will return an error if the selected base is not known.



Package multibase imports 8 packages (graph) and is imported by 54 packages. Updated 2020-05-26. Refresh now. Tools for package owners.