Golang encoding/base32.Encoding.EncodedLen function example

package encoding/base32

EncodedLen returns the length in bytes of the base32 encoding of an input buffer of length n(1st parameter).

Golang encoding/base32.Encoding.EncodedLen function usage example

 // Base32ExtEncode encodes binary data to base32 extended (RFC 4648) encoded text.
 func Base32ExtEncode(data []byte) (text []byte) {
 n := base32.HexEncoding.EncodedLen(len(data))  // <--- EncodedLen
 buf := bytes.NewBuffer(make([]byte, 0, n))
 encoder := base32.NewEncoder(base32.HexEncoding, buf)
 encoder.Write(data)
 encoder.Close()
 if buf.Len() != n {
 panic("internal error")
 }
 return buf.Bytes()
 }

Reference :

http://golang.org/pkg/encoding/base32/#Encoding.EncodedLen

Advertisement