basen

package
v1.66.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2022 License: BSD-3-Clause, MIT Imports: 4 Imported by: 10

README

basen (base-N) is a simple Go encoding package for representing bytes as big integers in arbitrary base-N encoding.

See https://godoc.org/github.com/cmars/basen for package documentation.

Documentation

Overview

Package basen basen (base-N) is a simple Go encoding package for representing bytes as big integers in arbitrary base-N encoding.

Index

Constants

This section is empty.

Variables

View Source
var Base58 = NewEncoding(base58Alphabet)

Base58 represents bytes as a base-58 number [1-9A-GHJ-LM-Za-z].

View Source
var Base62 = NewEncoding(base62Alphabet)

Base62 represents bytes as a base-62 number [0-9A-Za-z].

Functions

This section is empty.

Types

type Encoding

type Encoding struct {
	// contains filtered or unexported fields
}

Encoding represents a given base-N encoding.

func NewEncoding

func NewEncoding(alphabet string) *Encoding

NewEncoding creates a new base-N representation from the given alphabet. Panics if the alphabet is not unique. Only ASCII characters are supported.

func (*Encoding) Base

func (enc *Encoding) Base() int

Base returns the number base of the encoding.

func (*Encoding) DecodeString

func (enc *Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes for the given base-encoded string.

func (*Encoding) DecodeStringN

func (enc *Encoding) DecodeStringN(s string, n int) ([]byte, error)

DecodeStringN returns N bytes for the given base-encoded string. Use this method to ensure the value is left-padded with zeroes.

func (*Encoding) EncodeToString

func (enc *Encoding) EncodeToString(b []byte) string

EncodeToString returns the base-encoded string representation of the given bytes.

func (*Encoding) MustRandom

func (enc *Encoding) MustRandom(n int) string

MustRandom returns the base-encoded representation of n random bytes, panicking in the unlikely event of a read error from the random source.

func (*Encoding) Random

func (enc *Encoding) Random(n int) (string, error)

Random returns the base-encoded representation of n random bytes.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL