Golang encoding/base32.NewEncoder function examples
package encoding/base32
NewEncoder returns a new base32 stream encoder. Data written to the returned writer will be encoded using encoder type defined in 1st parameter and written to 2nd parameter. Base32 encodings operate in 5-byte blocks; when finished writing, the caller must Close the returned encoder to flush any partially written blocks.
Golang encoding/base32.NewEncoder function examples
Example 1 :
// Base32ExtEncode encodes binary data to base32 extended (RFC 4648) encoded text.
func Base32ExtEncode(data []byte) (text []byte) {
n := base32.HexEncoding.EncodedLen(len(data))
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()
}
Example 2 :
// Encodes things read from stdin into base32.
package main
import (
"encoding/base32"
"fmt"
"io"
"os"
)
func main() {
enc := base32.NewEncoder(base32.StdEncoding, os.Stdout)
if _, err := io.Copy(enc, os.Stdin); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
enc.Close()
fmt.Println()
}
References :
http://golang.org/pkg/encoding/base32/#NewEncoder
Advertisement
Something interesting
Tutorials
+18k Golang : Check if a directory exist or not
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+5.6k Golang : Shortening import identifier
+36.3k Golang : Convert(cast) int64 to string
+36k Golang : Get file last modified date and time
+5.7k Fix yum-complete-transaction error
+9.1k Golang : Simple histogram example
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+5k Golang : micron to centimeter example
+19k Golang : Padding data for encryption and un-padding data for decryption
+14k Golang : Reverse IP address for reverse DNS lookup example
+8.3k Golang : Oanda bot with Telegram and RSI example