https://github.com/eknkc/basex
Arbitrary base encoding in GO
https://github.com/eknkc/basex
base62 encoding go golang
Last synced: 11 months ago
JSON representation
Arbitrary base encoding in GO
- Host: GitHub
- URL: https://github.com/eknkc/basex
- Owner: eknkc
- License: mit
- Created: 2017-02-25T14:33:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-01-08T09:38:58.000Z (over 2 years ago)
- Last Synced: 2024-12-17T01:34:11.101Z (over 1 year ago)
- Topics: base62, encoding, go, golang
- Language: Go
- Size: 11.7 KB
- Stars: 55
- Watchers: 3
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# basex
[](https://github.com/eknkc/basex/actions)
import "github.com/eknkc/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
```go
type Encoding struct {
}
```
Encoding is a custom base encoding defined by an alphabet. It should be created
using NewEncoding function
#### func NewEncoding
```go
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
```go
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 error will
be returned
#### func (*Encoding) Encode
```go
func (e *Encoding) Encode(source []byte) string
```
Encode function receives a byte slice and encodes it to a string using the
alphabet provided