mirror of
https://github.com/golang/go
synced 2024-11-20 04:54:44 -07:00
encoding/base64: new example for NewEncoder with emphasis on Close
Fixes #4394. R=iant, bradfitz, rsc, remigius.gieben CC=golang-dev https://golang.org/cl/6847125
This commit is contained in:
parent
0d22573f6e
commit
15353d2114
@ -2,11 +2,14 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Keep in sync with ../base64/example_test.go.
|
||||||
|
|
||||||
package base32_test
|
package base32_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleEncoding_EncodeToString() {
|
func ExampleEncoding_EncodeToString() {
|
||||||
@ -28,3 +31,15 @@ func ExampleEncoding_DecodeString() {
|
|||||||
// Output:
|
// Output:
|
||||||
// "some data with \x00 and \ufeff"
|
// "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====
|
||||||
|
}
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Keep in sync with ../base32/example_test.go.
|
||||||
|
|
||||||
package base64_test
|
package base64_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleEncoding_EncodeToString() {
|
func ExampleEncoding_EncodeToString() {
|
||||||
@ -28,3 +31,15 @@ func ExampleEncoding_DecodeString() {
|
|||||||
// Output:
|
// Output:
|
||||||
// "some data with \x00 and \ufeff"
|
// "some data with \x00 and \ufeff"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleNewEncoder() {
|
||||||
|
input := []byte("foo\x00bar")
|
||||||
|
encoder := base64.NewEncoder(base64.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:
|
||||||
|
// Zm9vAGJhcg==
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user