From e3e77d4e9af6fe5dee53840c037fbc63b5667aed Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 6 Apr 2014 12:36:06 +0200 Subject: [PATCH] Add examples --- hashing/hashing_example_test.go | 33 ++++++++++++++++++++++++++ hashing/{implementation.go => impl.go} | 0 2 files changed, 33 insertions(+) create mode 100644 hashing/hashing_example_test.go rename hashing/{implementation.go => impl.go} (100%) diff --git a/hashing/hashing_example_test.go b/hashing/hashing_example_test.go new file mode 100644 index 000000000..ce5dedc1d --- /dev/null +++ b/hashing/hashing_example_test.go @@ -0,0 +1,33 @@ +package hashing_test + +import ( + "bytes" + "crypto/md5" + "crypto/sha1" + "fmt" + "strings" + + "github.com/fd0/khepri/hashing" +) + +func ExampleReader() { + str := "foobar" + reader := hashing.NewReader(strings.NewReader(str), md5.New) + buf := make([]byte, len(str)) + + reader.Read(buf) + + fmt.Printf("hash for %q is %02x", str, reader.Hash()) + // Output: hash for "foobar" is 3858f62230ac3c915f300c664312c63f +} + +func ExampleWriter() { + str := "foobar" + var buf bytes.Buffer + + writer := hashing.NewWriter(&buf, sha1.New) + writer.Write([]byte(str)) + + fmt.Printf("hash for %q is %02x", str, writer.Hash()) + // Output: hash for "foobar" is 8843d7f92416211de9ebb963ff4ce28125932878 +} diff --git a/hashing/implementation.go b/hashing/impl.go similarity index 100% rename from hashing/implementation.go rename to hashing/impl.go