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/0JhKF
Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<DJ+ .@<*K0@<6L(Df-\0Ec5dp
Reference :
See also : Golang encoding/ascii85.Decode function example
Advertisement
Something interesting
Tutorials
+13k Golang : Calculate elapsed years or months since a date
+5.3k Golang : Return multiple values from function
+31.4k Golang : bufio.NewReader.ReadLine to read file line by line
+5.7k Get website traffic ranking with Similar Web or Alexa
+18.6k Golang : Generate thumbnails from images
+9.1k Golang : How to capture return values from goroutines?
+12.7k Golang : Listen and Serve on sub domain example
+7k Golang : constant 20013 overflows byte error message
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+6.5k Elasticsearch : Shutdown a local node
+6k Golang : Missing Subversion command
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example