Standard library / encoding/base64

encoding/base64.Encoding.Decode()

Decodes into caller-allocated storage. Use the returned count rather than reading unused capacity. Expected stdout: '2 Go\n'.

Formal Syntax & Structure

go syntaxgo
func (enc *Encoding) Decode(dst, src []byte) (n int, err error)

Parameters & Attributes

NameTypeDescription
dst[]byteDestination byte slice; append APIs preserve its existing prefix.
src[]byteSource bytes to encode or decode.

Return Value

(n int, err error)

Bytes decoded and error.

Working Example

Example Snippetgo
package main
import (  "encoding/base64"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  p := make([]byte, base64.StdEncoding.DecodedLen(4))  n, e := base64.StdEncoding.Decode(p, []byte("R28="))  must(e)  fmt.Println(n, string(p[:n]))}
Go Reference