basex

package
v1.5.16 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: GPL-3.0, MIT Imports: 2 Imported by: 0

README

basex

Package basex provides fast base encoding / decoding of any given alphabet using bitcoin style leading zero compression. It is a GO port of https://github.com/cryptocoinjs/base-x

Usage

type Encoding
type Encoding struct {
}

Encoding is a custom base encoding defined by an alphabet. It should bre created using NewEncoding function

func NewEncoding
func NewEncoding(alphabet string) (*Encoding, error)

NewEncoding returns a custom base encoder defined by the alphabet string. The alphabet should contain non-repeating characters. Ordering is important. Example alphabets:

- base2: 01
- base16: 0123456789abcdef
- base32: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
- base62: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
func (*Encoding) Decode
func (e *Encoding) Decode(source string) ([]byte, error)

Decode function decodes a string previously obtained from Encode, using the same alphabet and returns a byte slice In case the input is not valid an arror will be returned

func (*Encoding) Encode
func (e *Encoding) Encode(source []byte) string

Encode function receives a byte slice and encodes it to a string using the alphabet provided

Documentation

Overview

Package basex provides fast base encoding / decoding of any given alphabet using bitcoin style leading zero compression. It is a GO port of https://github.com/cryptocoinjs/base-x

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonBaseChar       = errors.New("non-base character")
	ErrAmbiguousAlphabet = errors.New("ambiguous alphabet")
)

Functions

This section is empty.

Types

type Encoding

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

Encoding is a custom base encoding defined by an alphabet. It should bre created using NewEncoding function

func NewEncoding

func NewEncoding(alphabet string) (*Encoding, error)

NewEncoding returns a custom base encoder defined by the alphabet string. The alphabet should contain non-repeating characters. Ordering is important. Example alphabets:

  • base2: 01
  • base16: 0123456789abcdef
  • base32: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
  • base62: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

func (*Encoding) Decode

func (e *Encoding) Decode(source string) ([]byte, error)

Decode function decodes a string previously obtained from Encode, using the same alphabet and returns a byte slice In case the input is not valid an arror will be returned

func (*Encoding) Encode

func (e *Encoding) Encode(source []byte) string

Encode function receives a byte slice and encodes it to a string using the alphabet provided

Jump to

Keyboard shortcuts

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