diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/go/encoding%2Fbase32%2Findex.html | |
new repository
Diffstat (limited to 'devdocs/go/encoding%2Fbase32%2Findex.html')
| -rw-r--r-- | devdocs/go/encoding%2Fbase32%2Findex.html | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/devdocs/go/encoding%2Fbase32%2Findex.html b/devdocs/go/encoding%2Fbase32%2Findex.html new file mode 100644 index 00000000..d0c213b2 --- /dev/null +++ b/devdocs/go/encoding%2Fbase32%2Findex.html @@ -0,0 +1,96 @@ +<h1> Package base32 </h1> <ul id="short-nav"> +<li><code>import "encoding/base32"</code></li> +<li><a href="#pkg-overview" class="overviewLink">Overview</a></li> +<li><a href="#pkg-index" class="indexLink">Index</a></li> +<li><a href="#pkg-examples" class="examplesLink">Examples</a></li> +</ul> <h2 id="pkg-overview">Overview </h2> <p>Package base32 implements base32 encoding as specified by RFC 4648. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav"> +<li><a href="#pkg-constants">Constants</a></li> +<li><a href="#pkg-variables">Variables</a></li> +<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> +<li><a href="#CorruptInputError">type CorruptInputError</a></li> +<li> <a href="#CorruptInputError.Error">func (e CorruptInputError) Error() string</a> +</li> +<li><a href="#Encoding">type Encoding</a></li> +<li> <a href="#NewEncoding">func NewEncoding(encoder string) *Encoding</a> +</li> +<li> <a href="#Encoding.AppendDecode">func (enc *Encoding) AppendDecode(dst, src []byte) ([]byte, error)</a> +</li> +<li> <a href="#Encoding.AppendEncode">func (enc *Encoding) AppendEncode(dst, src []byte) []byte</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.DecodedLen">func (enc *Encoding) DecodedLen(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> +<li> <a href="#Encoding.EncodedLen">func (enc *Encoding) EncodedLen(n int) int</a> +</li> +<li> <a href="#Encoding.WithPadding">func (enc Encoding) WithPadding(padding rune) *Encoding</a> +</li> +</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_Encoding_Decode">Encoding.Decode</a></dd> <dd><a class="exampleLink" href="#example_Encoding_DecodeString">Encoding.DecodeString</a></dd> <dd><a class="exampleLink" href="#example_Encoding_Encode">Encoding.Encode</a></dd> <dd><a class="exampleLink" href="#example_Encoding_EncodeToString">Encoding.EncodeToString</a></dd> <dd><a class="exampleLink" href="#example_NewEncoder">NewEncoder</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>base32.go</span> </p> <h2 id="pkg-constants">Constants</h2> <pre data-language="go">const ( + StdPadding rune = '=' // Standard padding character + NoPadding rune = -1 // No padding +)</pre> <h2 id="pkg-variables">Variables</h2> <p>HexEncoding is the “Extended Hex Alphabet” defined in RFC 4648. It is typically used in DNS. </p> +<pre data-language="go">var HexEncoding = NewEncoding("0123456789ABCDEFGHIJKLMNOPQRSTUV")</pre> <p>StdEncoding is the standard base32 encoding, as defined in RFC 4648. </p> +<pre data-language="go">var StdEncoding = NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")</pre> <h2 id="NewDecoder">func <span>NewDecoder</span> </h2> <pre data-language="go">func NewDecoder(enc *Encoding, r io.Reader) io.Reader</pre> <p>NewDecoder constructs a new base32 stream decoder. </p> +<h2 id="NewEncoder">func <span>NewEncoder</span> </h2> <pre data-language="go">func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser</pre> <p>NewEncoder returns a new base32 stream encoder. Data written to the returned writer will be encoded using enc and then written to w. Base32 encodings operate in 5-byte blocks; when finished writing, the caller must Close the returned encoder to flush any partially written blocks. </p> <h4 id="example_NewEncoder"> <span class="text">Example</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">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() +</pre> <p>Output:</p> <pre class="output" data-language="go">MZXW6ADCMFZA==== +</pre> <h2 id="CorruptInputError">type <span>CorruptInputError</span> </h2> <pre data-language="go">type CorruptInputError int64</pre> <h3 id="CorruptInputError.Error">func (CorruptInputError) <span>Error</span> </h3> <pre data-language="go">func (e CorruptInputError) Error() string</pre> <h2 id="Encoding">type <span>Encoding</span> </h2> <p>An Encoding is a radix 32 encoding/decoding scheme, defined by a 32-character alphabet. The most common is the "base32" encoding introduced for SASL GSSAPI and standardized in RFC 4648. The alternate "base32hex" encoding is used in DNSSEC. </p> +<pre data-language="go">type Encoding struct { + // contains filtered or unexported fields +} +</pre> <h3 id="NewEncoding">func <span>NewEncoding</span> </h3> <pre data-language="go">func NewEncoding(encoder string) *Encoding</pre> <p>NewEncoding returns a new padded Encoding defined by the given alphabet, which must be a 32-byte string that contains unique byte values and does not contain the padding character or CR / LF ('\r', '\n'). The alphabet is treated as a sequence of byte values without any special treatment for multi-byte UTF-8. The resulting Encoding uses the default padding character ('='), which may be changed or disabled via <a href="#Encoding.WithPadding">Encoding.WithPadding</a>. </p> +<h3 id="Encoding.AppendDecode">func (*Encoding) <span>AppendDecode</span> <span title="Added in Go 1.22">1.22</span> </h3> <pre data-language="go">func (enc *Encoding) AppendDecode(dst, src []byte) ([]byte, error)</pre> <p>AppendDecode appends the base32 decoded src to dst and returns the extended buffer. If the input is malformed, it returns the partially decoded src and an error. </p> +<h3 id="Encoding.AppendEncode">func (*Encoding) <span>AppendEncode</span> <span title="Added in Go 1.22">1.22</span> </h3> <pre data-language="go">func (enc *Encoding) AppendEncode(dst, src []byte) []byte</pre> <p>AppendEncode appends the base32 encoded src to dst and returns the extended buffer. </p> +<h3 id="Encoding.Decode">func (*Encoding) <span>Decode</span> </h3> <pre data-language="go">func (enc *Encoding) Decode(dst, src []byte) (n int, err error)</pre> <p>Decode decodes src using the encoding enc. It writes at most <a href="#Encoding.DecodedLen">Encoding.DecodedLen</a>(len(src)) bytes to dst and returns the number of bytes written. If src contains invalid base32 data, it will return the number of bytes successfully written and <a href="#CorruptInputError">CorruptInputError</a>. Newline characters (\r and \n) are ignored. </p> <h4 id="example_Encoding_Decode"> <span class="text">Example</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">str := "JBSWY3DPFQQHO33SNRSCC===" +dst := make([]byte, base32.StdEncoding.DecodedLen(len(str))) +n, err := base32.StdEncoding.Decode(dst, []byte(str)) +if err != nil { + fmt.Println("decode error:", err) + return +} +dst = dst[:n] +fmt.Printf("%q\n", dst) +</pre> <p>Output:</p> <pre class="output" data-language="go">"Hello, world!" +</pre> <h3 id="Encoding.DecodeString">func (*Encoding) <span>DecodeString</span> </h3> <pre data-language="go">func (enc *Encoding) DecodeString(s string) ([]byte, error)</pre> <p>DecodeString returns the bytes represented by the base32 string s. </p> <h4 id="example_Encoding_DecodeString"> <span class="text">Example</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">str := "ONXW2ZJAMRQXIYJAO5UXI2BAAAQGC3TEEDX3XPY=" +data, err := base32.StdEncoding.DecodeString(str) +if err != nil { + fmt.Println("error:", err) + return +} +fmt.Printf("%q\n", data) +</pre> <p>Output:</p> <pre class="output" data-language="go">"some data with \x00 and \ufeff" +</pre> <h3 id="Encoding.DecodedLen">func (*Encoding) <span>DecodedLen</span> </h3> <pre data-language="go">func (enc *Encoding) DecodedLen(n int) int</pre> <p>DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base32-encoded data. </p> +<h3 id="Encoding.Encode">func (*Encoding) <span>Encode</span> </h3> <pre data-language="go">func (enc *Encoding) Encode(dst, src []byte)</pre> <p>Encode encodes src using the encoding enc, writing <a href="#Encoding.EncodedLen">Encoding.EncodedLen</a>(len(src)) bytes to dst. </p> +<p>The encoding pads the output to a multiple of 8 bytes, so Encode is not appropriate for use on individual blocks of a large data stream. Use <a href="#NewEncoder">NewEncoder</a> instead. </p> <h4 id="example_Encoding_Encode"> <span class="text">Example</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">data := []byte("Hello, world!") +dst := make([]byte, base32.StdEncoding.EncodedLen(len(data))) +base32.StdEncoding.Encode(dst, data) +fmt.Println(string(dst)) +</pre> <p>Output:</p> <pre class="output" data-language="go">JBSWY3DPFQQHO33SNRSCC=== +</pre> <h3 id="Encoding.EncodeToString">func (*Encoding) <span>EncodeToString</span> </h3> <pre data-language="go">func (enc *Encoding) EncodeToString(src []byte) string</pre> <p>EncodeToString returns the base32 encoding of src. </p> <h4 id="example_Encoding_EncodeToString"> <span class="text">Example</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">data := []byte("any + old & data") +str := base32.StdEncoding.EncodeToString(data) +fmt.Println(str) +</pre> <p>Output:</p> <pre class="output" data-language="go">MFXHSIBLEBXWYZBAEYQGIYLUME====== +</pre> <h3 id="Encoding.EncodedLen">func (*Encoding) <span>EncodedLen</span> </h3> <pre data-language="go">func (enc *Encoding) EncodedLen(n int) int</pre> <p>EncodedLen returns the length in bytes of the base32 encoding of an input buffer of length n. </p> +<h3 id="Encoding.WithPadding">func (Encoding) <span>WithPadding</span> <span title="Added in Go 1.9">1.9</span> </h3> <pre data-language="go">func (enc Encoding) WithPadding(padding rune) *Encoding</pre> <p>WithPadding creates a new encoding identical to enc except with a specified padding character, or NoPadding to disable padding. The padding character must not be '\r' or '\n', must not be contained in the encoding's alphabet, must not be negative, and must be a rune equal or below '\xff'. Padding characters above '\x7f' are encoded as their exact byte value rather than using the UTF-8 representation of the codepoint. </p><div class="_attribution"> + <p class="_attribution-p"> + © Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br> + <a href="http://golang.org/pkg/encoding/base32/" class="_attribution-link">http://golang.org/pkg/encoding/base32/</a> + </p> +</div> |
