1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-22 15:57:07 +00:00
restic/hashing_example_test.go

34 lines
671 B
Go
Raw Normal View History

2014-07-28 18:20:32 +00:00
package khepri_test
2014-04-06 10:36:06 +00:00
import (
"bytes"
"crypto/md5"
"crypto/sha1"
"fmt"
"strings"
2014-07-28 18:20:32 +00:00
"github.com/fd0/khepri"
2014-04-06 10:36:06 +00:00
)
func ExampleReader() {
str := "foobar"
2014-07-28 18:20:32 +00:00
reader := khepri.NewHashingReader(strings.NewReader(str), md5.New)
2014-04-06 10:36:06 +00:00
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
2014-07-28 18:20:32 +00:00
writer := khepri.NewHashingWriter(&buf, sha1.New)
2014-04-06 10:36:06 +00:00
writer.Write([]byte(str))
fmt.Printf("hash for %q is %02x", str, writer.Hash())
// Output: hash for "foobar" is 8843d7f92416211de9ebb963ff4ce28125932878
}