base91

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2017 License: BSD-3-Clause Imports: 1 Imported by: 5

README

base91-go

Travis Go Report Card Release License GoDoc

basE91 codec implemented in Golang.

Migrated from the C and PHP version of Joachim Henke's basE91.

Nodejs version

Install

$ go get -u ekyu.moe/base91

Example

package main

import (
    "fmt"

    "ekyu.moe/base91"
)

func main() {
    fmt.Println(base91.EncodeToString([]byte("Hello, 世界"))) //=> >OwJh>}AFU~PUh%Y
    fmt.Println(string(base91.DecodeString(">OwJh>}AFU~PUh%Y"))) //=> Hello, 世界
}

Check godoc for further documents.

A CLI utility is also available with go get ekyu.moe/base91/cmd/base91.

Benchmark

Note: 1 op = 1 MB input

$ go test --bench . --benchmem ekyu.moe/base91
goos: windows
goarch: amd64
pkg: ekyu.moe/base91
BenchmarkDecode-4            200           6484956 ns/op         7157760 B/op         36 allocs/op
BenchmarkDecoder-4           200           8789155 ns/op         146.71 MB/s     2136691 B/op      2465 allocs/op
BenchmarkEncode-4            300           7264316 ns/op         8673280 B/op         37 allocs/op
BenchmarkEncoder-4           200           7149004 ns/op         146.67 MB/s     2808690 B/op         2 allocs/op
PASS

License

BSD-3-clause

Documentation

Overview

Package base91 implements a base91 encoder and decoder.

base91 is defined in Joachim Henke's basE91: http://base91.sourceforge.net/

Example
package main

import (
	"fmt"

	"ekyu.moe/base91"
)

func main() {
	fmt.Println(base91.EncodeToString([]byte("Hello, 世界")))
	fmt.Println(string(base91.DecodeString(">OwJh>}AFU~PUh%Y")))
}
Output:

>OwJh>}AFU~PUh%Y
Hello, 世界

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	EmailLineWrap = 76
)

Functions

func Decode

func Decode(dst, src []byte) int

Decode decodes src into dst. It returns the number of bytes written to dst. Whereas base91 uses up to nearly all printable characters, Decode skips invalid characters silently.

func DecodeString

func DecodeString(s string) []byte

DecodeString returns the bytes represented by the base91 string s, probably what you want.

func Encode

func Encode(dst, src []byte) int

Encode encodes src into dst. It returns the number of bytes written to dst.

func EncodeToString

func EncodeToString(src []byte) string

EncodeToString returns the encoded base91 string of src, probably what you want.

func NewDecoder

func NewDecoder(r io.Reader) io.Reader

NewDecoder constructs a new base91 stream decoder. Data read from the returned reader is base91 decoded from r.

func NewEncoder

func NewEncoder(w io.Writer) io.WriteCloser

NewEncoder returns a new base91 stream encoder. Data written to the returned writer will be encoded using base91 and then written to w. When finished writing, the caller must Close the returned encoder to flush any partially written blocks.

func NewLineWrapper added in v0.2.0

func NewLineWrapper(w io.Writer, cols int) io.WriteCloser

NewLineWrapper returns an base91 encoeder that encode data and insert CRLF every cols characters. This is useful for emails.

Types

This section is empty.

Directories

Path Synopsis
cmd
base91
base91: a cli utility for base91 encode/decode.
base91: a cli utility for base91 encode/decode.

Jump to

Keyboard shortcuts

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