Ejemplo n.º 1
0
func TestEncodeBytes(t *testing.T) {
	for _, tc := range byteTests {
		dst := make([]byte, zbase32.EncodedLen(len(tc.decoded)))
		n := zbase32.Encode(dst, tc.decoded)
		dst = dst[:n]

		if g, e := string(dst), tc.encoded; g != e {
			t.Errorf("Encode %x wrong result: %q != %q", tc.decoded, g, e)
			continue
		}
	}
}
Ejemplo n.º 2
0
func main() {
	log.SetFlags(0)
	log.SetPrefix(prog + ": ")

	flag.Usage = usage
	flag.Parse()

	if flag.NArg() != 0 {
		usage()
		os.Exit(1)
	}

	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}
	encoded := make([]byte, zbase32.EncodedLen(len(data)))
	n := zbase32.Encode(encoded, data)
	encoded = encoded[:n]
	encoded = append(encoded, '\n')
	if _, err := os.Stdout.Write(encoded); err != nil {
		log.Fatal(err)
	}
}