Example #1
0
// 从 string 取得输入
func ExampleNewDecoder1() {

	src := "ORUGS4ZANFZSAYJAORSXG5BAON2HE2LOM4XA===="
	reader := strings.NewReader(src)

	dst := ""

	decoder := base32.NewDecoder(base32.StdEncoding, reader)
	// 使用一个很小的输出buffer,测试流式解码
	buf := make([]byte, 2)
	for {
		n, err := decoder.Read(buf)
		if err != nil {
			break
		}
		if n == 0 {
			break
		}
		dst += string(buf[0:n])
	}
	fmt.Print(dst)

	// Output:
	// this is a test string.

}
Example #2
0
// Base32ExtDecode decodes base32 extended (RFC 4648) text to binary data.
func Base32ExtDecode(text []byte) (data []byte, err error) {
	n := base32.HexEncoding.DecodedLen(len(text))
	data = make([]byte, n)
	decoder := base32.NewDecoder(base32.HexEncoding, bytes.NewBuffer(text))
	if n, err = decoder.Read(data); err != nil {
		n = 0
	}
	data = data[:n]
	return
}
Example #3
0
func main() {
	flag.Parse()
	var buffer bytes.Buffer
	enc := base32.NewEncoder(encoding(), io.MultiWriter(os.Stdout, &buffer))
	log.Println("encoding to stdout")
	_, err := enc.Write(data())
	enc.Close()
	if err != nil {
		log.Fatalf("failed encoding: %s", err)
	}
	println()
	dec := base32.NewDecoder(encoding(), &buffer)
	log.Println("decoding to stdout")
	io.Copy(os.Stdout, dec)
}