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
+15.9k Golang : Get current time from the Internet time server(ntp) example
+16.6k Golang : Delete files by extension
+7.2k Golang : Null and nil value
+11.3k Golang : How to flush a channel before the end of program?
+18.9k Golang : Read input from console line
+5.8k Linux : Disable and enable IPv4 forwarding
+10.2k Golang : Bcrypting password
+14.5k Golang : Find network of an IP address
+12.7k Golang : Sort and reverse sort a slice of bytes