Standard library / encoding/base64
encoding/base64.NewEncoder()
Wraps a writer to encode Base64. Close is required to flush the final partial quantum. Expected stdout: 'R28=\n'.
Formal Syntax & Structure
go syntaxgo
func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloserParameters & Attributes
| Name | Type | Description |
|---|---|---|
| enc | *Encoding | Base64 encoding configuration. |
| w | io.Writer | Output stream. |
Return Value
io.WriteCloser
Writer that must be closed to finish the stream.
Working Example
Example Snippetgo
package main
import ( "bytes" "encoding/base64" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var out bytes.Buffer w := base64.NewEncoder(base64.StdEncoding, &out) _, e := w.Write([]byte("Go")) must(e) must(w.Close()) fmt.Println(out.String())}