Golang encoding/ascii85.Encode function example

package encoding/ascii85

Encode encodes input source(2nd param) into at most MaxEncodedLen(len(src)) bytes of output(1st param), returning the actual number of bytes written.


The encoding handles 4-byte chunks, using a special encoding for the last fragment, so Encode is not appropriate for use on individual blocks of a large data stream. Use NewEncoder() instead.


Often, ascii85-encoded data is wrapped in <~ and ~> symbols. Encode does not add these.

Golang encoding/ascii85.Encode function usage example

 package main

 import (
 "encoding/ascii85"
 "fmt"
 )

 func main() {
  str :=  []byte("Man is distinguished, not only by his reason, but by this singular passion from")

  buffer := make([]byte, ascii85.MaxEncodedLen(len(str)))

  encodedbytes := ascii85.Encode(buffer, str)

  fmt.Println("Bytes written : ", encodedbytes)
  fmt.Println(string(buffer))

}

Output :

Bytes written : 99

9jqo^BlbD-BleB1DJ++F(f,q/0JhKFCj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<DJ+.@<*K0@<6L(Df-\0Ec5dp

Reference :

http://golang.org/pkg/encoding/ascii85/#Encode

  See also : Golang encoding/ascii85.Decode function example

Advertisement