From 66e99f683dfdf2acfd92ee91a820ef1645a4142f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 22 Apr 2022 21:15:46 +0800 Subject: [PATCH] edit README --- README.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4be425f..8bace7f 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,84 @@ base16384 interface of golang # Usage -## As package -Just import it in your project. -## As lib -Copy this repo to `$GOPATH/src`, then execute -```bash -go install -buildmode=shared -linkshared std -go install -buildmode=shared -linkshared base14 +## Quick start + +```go +package main + +import ( + "fmt" + + b14 "github.com/fumiama/go-base16384" +) + +func main() { + str := b14.EncodeString("1234567") + fmt.Println(str, b14.DecodeString(str)) +} ``` -Now you can use -```bash -go build -linkshared ... + +## API + +```go +func Encode(b []byte) (encd []byte) + +func EncodeLen(in int) (out int) + +func EncodeTo(b, encd []byte) error + +func EncodeToString(b []byte) string + +func EncodeFromString(s string) []byte + +func EncodeString(s string) string + +func DecodeLen(in, offset int) (out int) + +func Decode(b []byte) (decd []byte) + +func DecodeTo(b []byte, decd []byte) error + +func DecodeToString(d []byte) string + +func DecodeFromString(s string) []byte + +func DecodeString(s string) string ``` + +## Stream API + +```go +package main + +import ( + "bytes" + "crypto/rand" + "io" + + b14 "github.com/fumiama/go-base16384" +) + +func main() { + buf := make([]byte, 1024*1024+1) + _, err := rand.Read(buf) + if err != nil { + panic(err) + } + w := bytes.NewBuffer(make([]byte, 0, 1024*1024+1)) + e := b14.NewEncoder(bytes.NewReader(buf)) + _, err = io.Copy(w, e) + if err != nil { + panic(err) + } + w2 := bytes.NewBuffer(make([]byte, 0, 1024*1024+1)) + d := b14.NewDecoder(bytes.NewReader(w.Bytes())) + _, err = io.Copy(w2, d) + if err != nil { + panic(err) + } + if !bytes.Equal(buf, w2.Bytes()) { + panic("fail!") + } +} +``` \ No newline at end of file