1
2
3
4
5
6
7 package base32_test
8
9 import (
10 "encoding/base32"
11 "fmt"
12 "os"
13 )
14
15 func ExampleEncoding_EncodeToString() {
16 data := []byte("any + old & data")
17 str := base32.StdEncoding.EncodeToString(data)
18 fmt.Println(str)
19
20
21 }
22
23 func ExampleEncoding_Encode() {
24 data := []byte("Hello, world!")
25 dst := make([]byte, base32.StdEncoding.EncodedLen(len(data)))
26 base32.StdEncoding.Encode(dst, data)
27 fmt.Println(string(dst))
28
29
30 }
31
32 func ExampleEncoding_DecodeString() {
33 str := "ONXW2ZJAMRQXIYJAO5UXI2BAAAQGC3TEEDX3XPY="
34 data, err := base32.StdEncoding.DecodeString(str)
35 if err != nil {
36 fmt.Println("error:", err)
37 return
38 }
39 fmt.Printf("%q\n", data)
40
41
42 }
43
44 func ExampleEncoding_Decode() {
45 str := "JBSWY3DPFQQHO33SNRSCC==="
46 dst := make([]byte, base32.StdEncoding.DecodedLen(len(str)))
47 n, err := base32.StdEncoding.Decode(dst, []byte(str))
48 if err != nil {
49 fmt.Println("decode error:", err)
50 return
51 }
52 dst = dst[:n]
53 fmt.Printf("%q\n", dst)
54
55
56 }
57
58 func ExampleNewEncoder() {
59 input := []byte("foo\x00bar")
60 encoder := base32.NewEncoder(base32.StdEncoding, os.Stdout)
61 encoder.Write(input)
62
63
64
65 encoder.Close()
66
67
68 }
69
View as plain text