github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/encoding/base62.go (about) 1 package encoding 2 3 import ( 4 "github.com/eknkc/basex" 5 ) 6 7 const ( 8 // Base62Alphabet is the alphabet used for Base62 encoding. 9 Base62Alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 10 ) 11 12 // base62 is the Base62 encoder. It is safe for concurrent use. 13 var base62 *basex.Encoding 14 15 func init() { 16 // Initialize the Base62 encoder. 17 if encoding, err := basex.NewEncoding(Base62Alphabet); err != nil { 18 panic("unable to initialize Base62 encoder") 19 } else { 20 base62 = encoding 21 } 22 } 23 24 // EncodeBase62 performs Base62 encoding. 25 func EncodeBase62(value []byte) string { 26 return base62.Encode(value) 27 } 28 29 // DecodeBase62 performs Base62 decoding. 30 func DecodeBase62(value string) ([]byte, error) { 31 return base62.Decode(value) 32 }