summaryrefslogtreecommitdiffstats
path: root/src/encoding/base32/example_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
commit73df946d56c74384511a194dd01dbe099584fd1a (patch)
treefd0bcea490dd81327ddfbb31e215439672c9a068 /src/encoding/base32/example_test.go
parentInitial commit. (diff)
downloadgolang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.tar.xz
golang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.zip
Adding upstream version 1.16.10.upstream/1.16.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/encoding/base32/example_test.go')
-rw-r--r--src/encoding/base32/example_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/encoding/base32/example_test.go b/src/encoding/base32/example_test.go
new file mode 100644
index 0000000..2a302d8
--- /dev/null
+++ b/src/encoding/base32/example_test.go
@@ -0,0 +1,45 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Keep in sync with ../base64/example_test.go.
+
+package base32_test
+
+import (
+ "encoding/base32"
+ "fmt"
+ "os"
+)
+
+func ExampleEncoding_EncodeToString() {
+ data := []byte("any + old & data")
+ str := base32.StdEncoding.EncodeToString(data)
+ fmt.Println(str)
+ // Output:
+ // MFXHSIBLEBXWYZBAEYQGIYLUME======
+}
+
+func ExampleEncoding_DecodeString() {
+ str := "ONXW2ZJAMRQXIYJAO5UXI2BAAAQGC3TEEDX3XPY="
+ data, err := base32.StdEncoding.DecodeString(str)
+ if err != nil {
+ fmt.Println("error:", err)
+ return
+ }
+ fmt.Printf("%q\n", data)
+ // Output:
+ // "some data with \x00 and \ufeff"
+}
+
+func ExampleNewEncoder() {
+ input := []byte("foo\x00bar")
+ encoder := base32.NewEncoder(base32.StdEncoding, os.Stdout)
+ encoder.Write(input)
+ // Must close the encoder when finished to flush any partial blocks.
+ // If you comment out the following line, the last partial block "r"
+ // won't be encoded.
+ encoder.Close()
+ // Output:
+ // MZXW6ADCMFZA====
+}