# package base32
`import "encoding/base32"`
base32包实现了[RFC 4648](http://tools.ietf.org/html/rfc4648)规定的base32编码。
## Index
* [Variables](#pkg-variables)
* [type CorruptInputError](#CorruptInputError)
* [func (e CorruptInputError) Error() string](#CorruptInputError.Error)
* [type Encoding](#Encoding)
* [func NewEncoding(encoder string) \*Encoding](#NewEncoding)
* [func (enc \*Encoding) DecodedLen(n int) int](#Encoding.DecodedLen)
* [func (enc \*Encoding) Decode(dst, src []byte) (n int, err error)](#Encoding.Decode)
* [func (enc \*Encoding) DecodeString(s string) ([]byte, error)](#Encoding.DecodeString)
* [func (enc \*Encoding) EncodedLen(n int) int](#Encoding.EncodedLen)
* [func (enc \*Encoding) Encode(dst, src []byte)](#Encoding.Encode)
* [func (enc \*Encoding) EncodeToString(src []byte) string](#Encoding.EncodeToString)
* [func NewDecoder(enc \*Encoding, r io.Reader) io.Reader](#NewDecoder)
* [func NewEncoder(enc \*Encoding, w io.Writer) io.WriteCloser](#NewEncoder)
### Examples
* [Encoding.DecodeString](#example-Encoding-DecodeString)
* [Encoding.EncodeToString](#example-Encoding-EncodeToString)
* [NewEncoder](#example-NewEncoder)
## Variables
```
var HexEncoding = NewEncoding(encodeHex)
```
[RFC 4648](http://tools.ietf.org/html/rfc4648)定义的“扩展Hex字符集”,用于DNS。
```
var StdEncoding = NewEncoding(encodeStd)
```
[RFC 4648](http://tools.ietf.org/html/rfc4648)定义的标准base32编码字符集。
## type [CorruptInputError](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L230 "View Source")
```
type CorruptInputError int64
```
### func (CorruptInputError) [Error](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L232 "View Source")
```
func (e CorruptInputError) Error() string
```
## type [Encoding](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L23 "View Source")
```
type Encoding struct {
// 内含隐藏或非导出字段
}
```
双向的编码/解码协议,根据一个32字符的字符集定义,RFC 4648标准化了两种字符集。默认字符集用于SASI和GSSAPI,另一种用于DNSSEC。
### func [NewEncoding](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L33 "View Source")
```
func NewEncoding(encoder string) *Encoding
```
使用给出的字符集生成一个\*Encoding,字符集必须是32字节的字符串。
### func (\*Encoding) [DecodedLen](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L428 "View Source")
```
func (enc *Encoding) DecodedLen(n int) int
```
返回n字节base32编码的数据解码后的最大长度。
### func (\*Encoding) [Decode](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L323 "View Source")
```
func (enc *Encoding) Decode(dst, src []byte) (n int, err error)
```
将src的数据解码后存入dst,最多写DecodedLen(len(src))字节数据到dst,并返回写入的字节数。如果src包含非法字符,将返回成功写入的字符数和CorruptInputError。换行符(\r、\n)会被忽略。
### func (\*Encoding) [DecodeString](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L330 "View Source")
```
func (enc *Encoding) DecodeString(s string) ([]byte, error)
```
返回base32编码的字符串s代表的数据。
Example
```
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"
```
### func (\*Encoding) [EncodedLen](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L224 "View Source")
```
func (enc *Encoding) EncodedLen(n int) int
```
返回n字节数据进行base32编码后的最大长度。
### func (\*Encoding) [Encode](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L70 "View Source")
```
func (enc *Encoding) Encode(dst, src []byte)
```
将src的数据编码后存入dst,最多写EncodedLen(len(src))字节数据到dst,并返回写入的字节数。
函数会把输出设置为8的倍数,因此不建议对大数据流的独立数据块执行此方法,使用NewEncoder()代替。
### func (\*Encoding) [EncodeToString](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L138 "View Source")
```
func (enc *Encoding) EncodeToString(src []byte) string
```
返回将src编码后的字符串。
Example
```
data := []byte("any + old & data")
str := base32.StdEncoding.EncodeToString(data)
fmt.Println(str)
```
Output:
```
MFXHSIBLEBXWYZBAEYQGIYLUME======
```
## func [NewDecoder](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L422 "View Source")
```
func NewDecoder(enc *Encoding, r io.Reader) io.Reader
```
创建一个新的base32流解码器。
## func [NewEncoder](https://github.com/golang/go/blob/master/src/encoding/base32/base32.go#L218 "View Source")
```
func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
```
创建一个新的base32流编码器。写入的数据会在编码后再写入w,base32编码每5字节执行一次编码操作;写入完毕后,使用者必须调用Close方法以便将未写入的数据从缓存中刷新到w中。
Example
```
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====
```
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe