Import base85.go into tree

Upstream is not maintained last commit was six years ago and there
are various improvements to be had in the code
This commit is contained in:
Kovid Goyal
2023-09-04 20:29:20 +05:30
parent aad330135c
commit 0107d1cb89
7 changed files with 397 additions and 9 deletions

View File

@@ -0,0 +1,60 @@
package base85
import (
"testing"
"fmt"
)
func TestChunked (t *testing.T) {
a := []byte("M")
fmt.Printf("a %#v\n", a)
b := make([]byte, EncodedLen(len(a)))
encodeChunk(b, a)
fmt.Printf("b %#v\n", b)
c := make([]byte, DecodedLen(len(b)))
decodeChunk(c, b)
fmt.Printf("c %#v\n", c)
a = []byte("Ma")
fmt.Printf("a %#v\n", a)
b = make([]byte, EncodedLen(len(a)))
encodeChunk(b, a)
fmt.Printf("b %#v\n", b)
c = make([]byte, DecodedLen(len(b)))
decodeChunk(c, b)
fmt.Printf("c %#v\n", c)
a = []byte("Man")
fmt.Printf("a %#v\n", a)
b = make([]byte, EncodedLen(len(a)))
encodeChunk(b, a)
fmt.Printf("b %#v\n", b)
c = make([]byte, DecodedLen(len(b)))
decodeChunk(c, b)
fmt.Printf("c %#v\n", c)
a = []byte("Man ")
fmt.Printf("a %#v\n", a)
b = make([]byte, EncodedLen(len(a)))
encodeChunk(b, a)
fmt.Printf("b %#v\n", b)
c = make([]byte, DecodedLen(len(b)))
decodeChunk(c, b)
fmt.Printf("c %#v\n", c)
a = []byte("Manual")
fmt.Printf("a %#v\n", a)
b = make([]byte, EncodedLen(len(a)))
n := Encode(b, a)
fmt.Printf("b %#v %d\n", b, n)
c = make([]byte, DecodedLen(len(b)))
n, _ = Decode(c, b)
fmt.Printf("c %#v %d\n", c, n)
a = []byte("Manual")
fmt.Printf("a %s\n", a)
sb := EncodeToString(a) + "\""
fmt.Printf("b %#v\n", sb)
sc, err := DecodeString(sb)
fmt.Printf("c %s %s\n", sc, err)
}