[go] encoding/base64: Add examples for Encode/Decode

25 views
Skip to first unread message

jiahua wang (Gerrit)

unread,
Sep 8, 2021, 1:17:41 PM9/8/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

jiahua wang uploaded patch set #2 to this change.

View Change

encoding/base64: Add examples for Encode/Decode

Fixes: golang/go#37595
Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
---
M src/encoding/base64/example_test.go
1 file changed, 22 insertions(+), 0 deletions(-)

To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
Gerrit-Change-Number: 348394
Gerrit-PatchSet: 2
Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-MessageType: newpatchset

jiahua wang (Gerrit)

unread,
Sep 8, 2021, 1:17:41 PM9/8/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

jiahua wang has uploaded this change for review.

View Change

encoding/base64: Add examples for Encode/Decode

Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
---
M src/encoding/base64/example_test.go
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/encoding/base64/example_test.go b/src/encoding/base64/example_test.go
index 73f119a..5c2bf89 100644
--- a/src/encoding/base64/example_test.go
+++ b/src/encoding/base64/example_test.go
@@ -35,6 +35,15 @@
// YW55ICsgb2xkICYgZGF0YQ==
}

+func ExampleEncoding_Encode() {
+ data := []byte("Hello, world!")
+ dst := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
+ base64.StdEncoding.Encode(dst, data)
+ fmt.Println(string(dst))
+ // Output:
+ // SGVsbG8sIHdvcmxkIQ==
+}
+
func ExampleEncoding_DecodeString() {
str := "c29tZSBkYXRhIHdpdGggACBhbmQg77u/"
data, err := base64.StdEncoding.DecodeString(str)
@@ -47,6 +56,19 @@
// "some data with \x00 and \ufeff"
}

+func ExampleEncoding_Decode() {
+ str := "SGVsbG8sIHdvcmxkIQ=="
+ dst := make([]byte, base64.StdEncoding.DecodedLen(len(str)))
+ n, err := base64.StdEncoding.Decode(dst, []byte(str))
+ if err != nil {
+ fmt.Println("decode error:", err)
+ return
+ }
+ fmt.Printf("%q: %d\n", dst, n)
+ // Output:
+ // "Hello, world!\x00\x00": 13
+}
+
func ExampleNewEncoder() {
input := []byte("foo\x00bar")
encoder := base64.NewEncoder(base64.StdEncoding, os.Stdout)

To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
Gerrit-Change-Number: 348394
Gerrit-PatchSet: 1
Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
Gerrit-MessageType: newchange

jiahua wang (Gerrit)

unread,
Sep 11, 2021, 10:37:52 PM9/11/21
to goph...@pubsubhelper.golang.org, Russ Cox, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Russ Cox.

Patch set 2:Code-Review +1

View Change

    To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
    Gerrit-Change-Number: 348394
    Gerrit-PatchSet: 2
    Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-Comment-Date: Sun, 12 Sep 2021 02:37:44 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    jiahua wang (Gerrit)

    unread,
    Sep 16, 2021, 6:51:36 AM9/16/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Russ Cox.

    jiahua wang uploaded patch set #3 to this change.

    View Change

    encoding/base64: Add examples for Encode/Decode

    Fixes: golang/go#37595

    Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
    ---
    M src/encoding/base64/example_test.go
    1 file changed, 22 insertions(+), 0 deletions(-)

    To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
    Gerrit-Change-Number: 348394
    Gerrit-PatchSet: 3
    Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-MessageType: newpatchset

    Ian Lance Taylor (Gerrit)

    unread,
    Oct 1, 2021, 8:30:23 PM10/1/21
    to jiahua wang, goph...@pubsubhelper.golang.org, Russ Cox, Go Bot, golang-co...@googlegroups.com

    Attention is currently required from: jiahua wang, Russ Cox.

    Patch set 3:Run-TryBot +1

    View Change

    1 comment:

    To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
    Gerrit-Change-Number: 348394
    Gerrit-PatchSet: 3
    Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-Comment-Date: Sat, 02 Oct 2021 00:30:18 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    jiahua wang (Gerrit)

    unread,
    Oct 1, 2021, 8:34:04 PM10/1/21
    to jiahua wang, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: jiahua wang, Russ Cox.

    jiahua wang uploaded patch set #4 to this change.

    View Change

    encoding/base64: add examples for Encode/Decode


    Fixes: golang/go#37595
    Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
    ---
    M src/encoding/base64/example_test.go
    1 file changed, 32 insertions(+), 0 deletions(-)

    To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
    Gerrit-Change-Number: 348394
    Gerrit-PatchSet: 4
    Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-MessageType: newpatchset

    Ian Lance Taylor (Gerrit)

    unread,
    Oct 1, 2021, 8:44:03 PM10/1/21
    to jiahua wang, goph...@pubsubhelper.golang.org, Russ Cox, Go Bot, golang-co...@googlegroups.com

    Attention is currently required from: jiahua wang, Russ Cox.

    Patch set 4:Run-TryBot +1

    View Change

      To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
      Gerrit-Change-Number: 348394
      Gerrit-PatchSet: 4
      Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
      Gerrit-CC: Go Bot <go...@golang.org>
      Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Sat, 02 Oct 2021 00:43:57 +0000

      Ian Lance Taylor (Gerrit)

      unread,
      Oct 1, 2021, 10:23:55 PM10/1/21
      to jiahua wang, goph...@pubsubhelper.golang.org, Go Bot, Russ Cox, golang-co...@googlegroups.com

      Attention is currently required from: jiahua wang, Russ Cox.

      View Change

      1 comment:

      • File src/encoding/base64/example_test.go:

        • Patch Set #4, Line 67: fmt.Printf("%q: %d\n", dst, n)

          This should be like the encoding/base32 example. dst = dst[:n] and then just print dst.

      To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
      Gerrit-Change-Number: 348394
      Gerrit-PatchSet: 4
      Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Sat, 02 Oct 2021 02:23:49 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment

      jiahua wang (Gerrit)

      unread,
      Oct 2, 2021, 12:11:08 AM10/2/21
      to jiahua wang, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: jiahua wang, Russ Cox.

      jiahua wang uploaded patch set #5 to this change.

      View Change

      encoding/base64: add examples for Encode/Decode

      Fixes golang/go#37595
      Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
      ---
      M src/encoding/base64/example_test.go
      1 file changed, 33 insertions(+), 0 deletions(-)

      To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
      Gerrit-Change-Number: 348394
      Gerrit-PatchSet: 5
      Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: Russ Cox <r...@golang.org>
      Gerrit-MessageType: newpatchset

      Ian Lance Taylor (Gerrit)

      unread,
      Oct 5, 2021, 7:10:16 PM10/5/21
      to jiahua wang, goph...@pubsubhelper.golang.org, Go Bot, Russ Cox, golang-co...@googlegroups.com

      Attention is currently required from: jiahua wang, Russ Cox.

      Patch set 5:Run-TryBot +1

      View Change

      1 comment:

      • File src/encoding/base64/example_test.go:

        • Patch Set #4, Line 67: fmt.Printf("%q: %d\n", dst, n)

          This should be like the encoding/base32 example. dst = dst[:n] and then just print dst.

        • Done

      To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
      Gerrit-Change-Number: 348394
      Gerrit-PatchSet: 5
      Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
      Gerrit-Attention: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Tue, 05 Oct 2021 23:10:11 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Ian Lance Taylor <ia...@golang.org>
      Gerrit-MessageType: comment

      Ian Lance Taylor (Gerrit)

      unread,
      Oct 5, 2021, 7:58:59 PM10/5/21
      to jiahua wang, goph...@pubsubhelper.golang.org, Go Bot, Russ Cox, golang-co...@googlegroups.com

      Attention is currently required from: jiahua wang, Russ Cox.

      Patch set 6:Run-TryBot +1

      View Change

        To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Gerrit-Change-Number: 348394
        Gerrit-PatchSet: 6
        Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: Russ Cox <r...@golang.org>
        Gerrit-Comment-Date: Tue, 05 Oct 2021 23:58:53 +0000

        Ian Lance Taylor (Gerrit)

        unread,
        Oct 5, 2021, 8:34:26 PM10/5/21
        to jiahua wang, goph...@pubsubhelper.golang.org, Go Bot, Russ Cox, golang-co...@googlegroups.com

        Attention is currently required from: jiahua wang, Russ Cox.

        Patch set 6:Code-Review +2

        View Change

        1 comment:

        To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Gerrit-Change-Number: 348394
        Gerrit-PatchSet: 6
        Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: Russ Cox <r...@golang.org>
        Gerrit-Comment-Date: Wed, 06 Oct 2021 00:34:20 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Gerrit-MessageType: comment

        Cherry Mui (Gerrit)

        unread,
        Oct 18, 2021, 6:06:00 PM10/18/21
        to jiahua wang, Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go Bot, Russ Cox, golang-co...@googlegroups.com

        Attention is currently required from: jiahua wang, Ian Lance Taylor, Russ Cox.

        Patch set 6:Trust +1

        View Change

        2 comments:

        • Commit Message:

          • Ack

        • Commit Message:

          • Patch Set #6, Line 9: Fixes golang/go#37595

            Minor: remove "golang/go" as this is already the Go repo. Also, add a blank line
            after this line before the change ID line. Thanks.

        To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Gerrit-Change-Number: 348394
        Gerrit-PatchSet: 6
        Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Russ Cox <r...@golang.org>
        Gerrit-Comment-Date: Mon, 18 Oct 2021 22:05:56 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes

        jiahua wang (Gerrit)

        unread,
        Oct 18, 2021, 9:55:42 PM10/18/21
        to jiahua wang, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

        Attention is currently required from: jiahua wang, Ian Lance Taylor, Russ Cox.

        jiahua wang uploaded patch set #7 to this change.

        View Change

        encoding/base64: add examples for Encode/Decode

        Fixes #37595


        Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        ---
        M src/encoding/base64/example_test.go
        1 file changed, 34 insertions(+), 0 deletions(-)

        To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Gerrit-Change-Number: 348394
        Gerrit-PatchSet: 7
        Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Russ Cox <r...@golang.org>
        Gerrit-MessageType: newpatchset

        Daniel Martí (Gerrit)

        unread,
        Oct 19, 2021, 4:44:17 AM10/19/21
        to jiahua wang, goph...@pubsubhelper.golang.org, Cherry Mui, Ian Lance Taylor, Go Bot, Russ Cox, golang-co...@googlegroups.com

        Attention is currently required from: jiahua wang, Ian Lance Taylor, Russ Cox.

        Patch set 7:Code-Review +2Trust +1

        View Change

        1 comment:

        • Patchset:

          • Patch Set #7:

            PS7 just updates the commit message, and PS6 passed the tests. Submitting.

        To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Gerrit-Change-Number: 348394
        Gerrit-PatchSet: 7
        Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Russ Cox <r...@golang.org>
        Gerrit-Comment-Date: Tue, 19 Oct 2021 08:44:12 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Gerrit-MessageType: comment

        Daniel Martí (Gerrit)

        unread,
        Oct 19, 2021, 4:44:28 AM10/19/21
        to jiahua wang, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Cherry Mui, Ian Lance Taylor, Go Bot, Russ Cox, golang-co...@googlegroups.com

        Daniel Martí submitted this change.

        View Change


        Approvals: Ian Lance Taylor: Looks good to me, approved Daniel Martí: Looks good to me, approved; Trusted Cherry Mui: Trusted
        encoding/base64: add examples for Encode/Decode

        Fixes #37595

        Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Reviewed-on: https://go-review.googlesource.com/c/go/+/348394
        Reviewed-by: Daniel Martí <mv...@mvdan.cc>
        Reviewed-by: Ian Lance Taylor <ia...@golang.org>
        Trust: Daniel Martí <mv...@mvdan.cc>
        Trust: Cherry Mui <cher...@google.com>
        ---
        M src/encoding/base64/example_test.go
        1 file changed, 39 insertions(+), 0 deletions(-)

        diff --git a/src/encoding/base64/example_test.go b/src/encoding/base64/example_test.go
        index 73f119a..61a3adc 100644

        --- a/src/encoding/base64/example_test.go
        +++ b/src/encoding/base64/example_test.go
        @@ -35,6 +35,15 @@
        // YW55ICsgb2xkICYgZGF0YQ==
        }

        +func ExampleEncoding_Encode() {
        + data := []byte("Hello, world!")
        + dst := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
        + base64.StdEncoding.Encode(dst, data)
        + fmt.Println(string(dst))
        + // Output:
        + // SGVsbG8sIHdvcmxkIQ==
        +}
        +
        func ExampleEncoding_DecodeString() {
        str := "c29tZSBkYXRhIHdpdGggACBhbmQg77u/"
        data, err := base64.StdEncoding.DecodeString(str)
        @@ -47,6 +56,20 @@

        // "some data with \x00 and \ufeff"
        }

        +func ExampleEncoding_Decode() {
        + str := "SGVsbG8sIHdvcmxkIQ=="
        + dst := make([]byte, base64.StdEncoding.DecodedLen(len(str)))
        + n, err := base64.StdEncoding.Decode(dst, []byte(str))
        + if err != nil {
        + fmt.Println("decode error:", err)
        + return
        + }
        +	dst = dst[:n]
        + fmt.Printf("%q\n", dst)

        + // Output:
        + // "Hello, world!"
        +}
        +
        func ExampleNewEncoder() {
        input := []byte("foo\x00bar")
        encoder := base64.NewEncoder(base64.StdEncoding, os.Stdout)

        To view, visit change 348394. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I83e5f6105748a0a9238322a4f7ec4b0bbf61a263
        Gerrit-Change-Number: 348394
        Gerrit-PatchSet: 8
        Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: jiahua wang <wjh1...@gmail.com>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages