Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
05e4e805
Commit
05e4e805
authored
Oct 08, 2012
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding/base{32,64}: add examples.
Fixes #4136. R=golang-dev, r CC=golang-dev
https://golang.org/cl/6615061
parent
c7cc894e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
example_test.go
src/pkg/encoding/base32/example_test.go
+30
-0
example_test.go
src/pkg/encoding/base64/example_test.go
+30
-0
No files found.
src/pkg/encoding/base32/example_test.go
0 → 100644
View file @
05e4e805
// 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.
package
base32_test
import
(
"encoding/base32"
"fmt"
)
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"
}
src/pkg/encoding/base64/example_test.go
0 → 100644
View file @
05e4e805
// 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.
package
base64_test
import
(
"encoding/base64"
"fmt"
)
func
ExampleEncoding_EncodeToString
()
{
data
:=
[]
byte
(
"any + old & data"
)
str
:=
base64
.
StdEncoding
.
EncodeToString
(
data
)
fmt
.
Println
(
str
)
// Output:
// YW55ICsgb2xkICYgZGF0YQ==
}
func
ExampleEncoding_DecodeString
()
{
str
:=
"c29tZSBkYXRhIHdpdGggACBhbmQg77u/"
data
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
str
)
if
err
!=
nil
{
fmt
.
Println
(
"error:"
,
err
)
return
}
fmt
.
Printf
(
"%q
\n
"
,
data
)
// Output:
// "some data with \x00 and \ufeff"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment