base62

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package base62 provides base62 encoding and decoding functionality. Base62 encoding uses digits 0-9, uppercase letters A-Z, and lowercase letters a-z. This provides a URL-safe, case-sensitive encoding that's more compact than base64 and doesn't require padding characters.

Example usage:

// Encode bytes to base62
encoded := base62.StdEncoding.EncodeToString([]byte("Hello, World!"))
fmt.Println(encoded)

// Decode base62 string back to bytes
decoded, err := base62.StdEncoding.DecodeString(encoded)
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(decoded))

Index

Constants

This section is empty.

Variables

View Source
var StdEncoding = NewEncoding(encodeStd)

StdEncoding is the standard base62 encoding.

Functions

This section is empty.

Types

type CorruptInputError

type CorruptInputError int64

func (CorruptInputError) Error

func (e CorruptInputError) Error() string

type Encoding

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

An Encoding is a radix 62 encoding/decoding scheme, defined by a 62-character alphabet.

func NewEncoding

func NewEncoding(encoder string) *Encoding

NewEncoding returns a new padded Encoding defined by the given alphabet, which must be a 62-byte string that does not contain the padding character or CR / LF ('\r', '\n').

func (*Encoding) Decode

func (enc *Encoding) Decode(src []byte) ([]byte, error)

Decode decodes src using the encoding enc. If src contains invalid base62 data, it will return the number of bytes successfully written and CorruptInputError. New line characters (\r and \n) are ignored.

func (*Encoding) DecodeString

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

DecodeString returns the bytes represented by the base62 string s.

func (*Encoding) Encode

func (enc *Encoding) Encode(src []byte) []byte

Encode encodes src using the encoding enc.

func (*Encoding) EncodeToString

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

EncodeToString returns the base62 encoding of src.

Jump to

Keyboard shortcuts

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