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 :
Advertisement
Something interesting
Tutorials
+6.9k Golang : Normalize email to prevent multiple signups example
+6.9k Nginx : Password protect a directory/folder
+35.9k Golang : Integer is between a range
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+5.6k Unix/Linux : How to find out the hard disk size?
+13.6k Golang : reCAPTCHA example
+16.3k Golang :Trim white spaces from a string
+8.3k Golang : Implementing class(object-oriented programming style)
+8.8k Golang : Executing and evaluating nested loop in html template
+8.8k Yum Error: no such table: packages
+10.9k Golang : Get UDP client IP address and differentiate clients by port number