-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathencoding_base32.htm
150 lines (149 loc) · 12 KB
/
encoding_base32.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head profile="http://a9.com/-/spec/opensearch/1.1/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../assets/site.css" rel="stylesheet">
<title>encoding/base32</title>
</head>
<body>
<div class="container">
<h2 id="pkg-overview">package base32</h2>
<p><code>import "encoding/base32"</code>
<p>base32包实现了<a href="http://tools.ietf.org/html/rfc4648">RFC 4648</a>规定的base32编码。</p>
<h3 id="pkg-index" class="section-header">Index <a class="permalink" href="#pkg-index">¶</a></h3>
<a href="../main.html"><h3>返回首页</h3></a>
</br>
<li><a href="#pkg-variables">Variables</a></li>
<li><a href="#CorruptInputError">type CorruptInputError</a></li>
<ul>
<li><a href="#CorruptInputError.Error">func (e CorruptInputError) Error() string</a></li>
</ul>
<li><a href="#Encoding">type Encoding</a></li>
<ul>
<li><a href="#NewEncoding">func NewEncoding(encoder string) *Encoding</a></li>
<li><a href="#Encoding.DecodedLen">func (enc *Encoding) DecodedLen(n int) int</a></li>
<li><a href="#Encoding.Decode">func (enc *Encoding) Decode(dst, src []byte) (n int, err error)</a></li>
<li><a href="#Encoding.DecodeString">func (enc *Encoding) DecodeString(s string) ([]byte, error)</a></li>
<li><a href="#Encoding.EncodedLen">func (enc *Encoding) EncodedLen(n int) int</a></li>
<li><a href="#Encoding.Encode">func (enc *Encoding) Encode(dst, src []byte)</a></li>
<li><a href="#Encoding.EncodeToString">func (enc *Encoding) EncodeToString(src []byte) string</a></li>
</ul>
<li><a href="#NewDecoder">func NewDecoder(enc *Encoding, r io.Reader) io.Reader</a></li>
<li><a href="#NewEncoder">func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser</a></li>
</ul>
<h4 id="pkg-examples">Examples <a class="permalink" href="#pkg-index">¶</a></h4>
<a href="../main.html"><h3>返回首页</h3></a>
</br>
<li><a href="#example-Encoding-DecodeString" onclick="$('#ex-Encoding-DecodeString').addClass('in').removeClass('collapse').height('auto')">Encoding.DecodeString</a></li>
<li><a href="#example-Encoding-EncodeToString" onclick="$('#ex-Encoding-EncodeToString').addClass('in').removeClass('collapse').height('auto')">Encoding.EncodeToString</a></li>
<li><a href="#example-NewEncoder" onclick="$('#ex-NewEncoder').addClass('in').removeClass('collapse').height('auto')">NewEncoder</a></li>
</ul>
<h3 id="pkg-variables">Variables <a class="permalink" href="#pkg-index">¶</a></h3>
<pre>var <span id="HexEncoding">HexEncoding</span> = <a href="#NewEncoding">NewEncoding</a>(encodeHex)</pre>
<p><a href="http://tools.ietf.org/html/rfc4648">RFC 4648</a>定义的“扩展Hex字符集”,用于DNS。</p>
<pre>var <span id="StdEncoding">StdEncoding</span> = <a href="#NewEncoding">NewEncoding</a>(encodeStd)</pre>
<p><a href="http://tools.ietf.org/html/rfc4648">RFC 4648</a>定义的标准base32编码字符集。</p>
<h3 id="CorruptInputError">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#230">CorruptInputError</a> <a class="permalink" href="#pkg-index">¶</a></h3>
<pre>type CorruptInputError <a href="builtin.htm#int64">int64</a></pre>
<h4 id="CorruptInputError.Error">func (CorruptInputError) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#232">Error</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (e <a href="#CorruptInputError">CorruptInputError</a>) Error() <a href="builtin.htm#string">string</a></pre>
<h3 id="Encoding">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#23">Encoding</a> <a class="permalink" href="#pkg-index">¶</a></h3>
<pre>type Encoding struct {
<span class="com">// 内含隐藏或非导出字段</span>
}</pre>
<p>双向的编码/解码协议,根据一个32字符的字符集定义,RFC 4648标准化了两种字符集。默认字符集用于SASI和GSSAPI,另一种用于DNSSEC。</p>
<h4 id="NewEncoding">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#33">NewEncoding</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func NewEncoding(encoder <a href="builtin.htm#string">string</a>) *<a href="#Encoding">Encoding</a></pre>
<p>使用给出的字符集生成一个*Encoding,字符集必须是32字节的字符串。</p>
<h4 id="Encoding.DecodedLen">func (*Encoding) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#428">DecodedLen</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (enc *<a href="#Encoding">Encoding</a>) DecodedLen(n <a href="builtin.htm#int">int</a>) <a href="builtin.htm#int">int</a></pre>
<p>返回n字节base32编码的数据解码后的最大长度。</p>
<h4 id="Encoding.Decode">func (*Encoding) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#323">Decode</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (enc *<a href="#Encoding">Encoding</a>) Decode(dst, src []<a href="builtin.htm#byte">byte</a>) (n <a href="builtin.htm#int">int</a>, err <a href="builtin.htm#error">error</a>)</pre>
<p>将src的数据解码后存入dst,最多写DecodedLen(len(src))字节数据到dst,并返回写入的字节数。如果src包含非法字符,将返回成功写入的字符数和CorruptInputError。换行符(\r、\n)会被忽略。</p>
<h4 id="Encoding.DecodeString">func (*Encoding) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#330">DecodeString</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (enc *<a href="#Encoding">Encoding</a>) DecodeString(s <a href="builtin.htm#string">string</a>) ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
<p>返回base32编码的字符串s代表的数据。</p>
<div class="panel-group">
<div class="panel panel-default" id="example-Encoding-DecodeString">
<div class="panel-heading" onclick="document.getElementById('ex-Encoding-DecodeString').style.display = document.getElementById('ex-Encoding-DecodeString').style.display=='none'?'block':'none';">Example</div>
<div id="ex-Encoding-DecodeString" class="panel-collapse collapse">
<div class="panel-body">
<pre>str := "ONXW2ZJAMRQXIYJAO5UXI2BAAAQGC3TEEDX3XPY="
data, err := base32.StdEncoding.DecodeString(str)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Printf("%q\n", data)</pre>
<p>Output:
<pre>"some data with \x00 and \ufeff"
</pre>
</div>
</div>
</div>
</div>
<h4 id="Encoding.EncodedLen">func (*Encoding) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#224">EncodedLen</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (enc *<a href="#Encoding">Encoding</a>) EncodedLen(n <a href="builtin.htm#int">int</a>) <a href="builtin.htm#int">int</a></pre>
<p>返回n字节数据进行base32编码后的最大长度。</p>
<h4 id="Encoding.Encode">func (*Encoding) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#70">Encode</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (enc *<a href="#Encoding">Encoding</a>) Encode(dst, src []<a href="builtin.htm#byte">byte</a>)</pre>
<p>将src的数据编码后存入dst,最多写EncodedLen(len(src))字节数据到dst,并返回写入的字节数。</p>
<p>函数会把输出设置为8的倍数,因此不建议对大数据流的独立数据块执行此方法,使用NewEncoder()代替。</p>
<h4 id="Encoding.EncodeToString">func (*Encoding) <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#138">EncodeToString</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (enc *<a href="#Encoding">Encoding</a>) EncodeToString(src []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#string">string</a></pre>
<p>返回将src编码后的字符串。</p>
<div class="panel-group">
<div class="panel panel-default" id="example-Encoding-EncodeToString">
<div class="panel-heading" onclick="document.getElementById('ex-Encoding-EncodeToString').style.display = document.getElementById('ex-Encoding-EncodeToString').style.display=='none'?'block':'none';">Example</div>
<div id="ex-Encoding-EncodeToString" class="panel-collapse collapse">
<div class="panel-body">
<pre>data := []byte("any + old & data")
str := base32.StdEncoding.EncodeToString(data)
fmt.Println(str)</pre>
<p>Output:
<pre>MFXHSIBLEBXWYZBAEYQGIYLUME======
</pre>
</div>
</div>
</div>
</div>
<h3 id="NewDecoder">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#422">NewDecoder</a> <a class="permalink" href="#pkg-index">¶</a></h3>
<pre class="funcdecl">func NewDecoder(enc *<a href="#Encoding">Encoding</a>, r <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a>) <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a></pre>
<p>创建一个新的base32流解码器。</p>
<h3 id="NewEncoder">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/encoding/base32/base32.go?name=release#218">NewEncoder</a> <a class="permalink" href="#pkg-index">¶</a></h3>
<pre class="funcdecl">func NewEncoder(enc *<a href="#Encoding">Encoding</a>, w <a href="io.htm">io</a>.<a href="io.htm#Writer">Writer</a>) <a href="io.htm">io</a>.<a href="io.htm#WriteCloser">WriteCloser</a></pre>
<p>创建一个新的base32流编码器。写入的数据会在编码后再写入w,base32编码每5字节执行一次编码操作;写入完毕后,使用者必须调用Close方法以便将未写入的数据从缓存中刷新到w中。</p>
<div class="panel-group">
<div class="panel panel-default" id="example-NewEncoder">
<div class="panel-heading" onclick="document.getElementById('ex-NewEncoder').style.display = document.getElementById('ex-NewEncoder').style.display=='none'?'block':'none';">Example</div>
<div id="ex-NewEncoder" class="panel-collapse collapse">
<div class="panel-body">
<pre>input := []byte("foo\x00bar")
encoder := base32.NewEncoder(base32.StdEncoding, os.Stdout)
encoder.Write(input)
<span class="com">// Must close the encoder when finished to flush any partial blocks.</span>
<span class="com">// If you comment out the following line, the last partial block "r"</span>
<span class="com">// won't be encoded.</span>
encoder.Close()</pre>
<p>Output:
<pre>MZXW6ADCMFZA====
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="x-footer" class="clearfix">
<div class="container">
<a href="http://studygolang.com/" target="_blank">Go语言中文网</a>
<span class="text-muted">|</span> <a href="http://golang.org/" target="_blank">Go Language</a>
<span class="pull-right"><a href="#">Back to top</a></span>
</div>
</div>
<script src="../assets/jquery-2.0.3.min.js"></script>
<script src="../assets/bootstrap.min.js"></script>
<script src="../assets/site.js"></script>
</body>
</html>