aboutsummaryrefslogtreecommitdiff
path: root/object.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-09-03 11:07:52 +0000
committerGitHub <noreply@github.com>2018-09-03 11:07:52 +0000
commitf9be896d5fd937c64a95797ced7ce887103518c8 (patch)
tree4cedb2b880d5a6a8b9908460a1f5dd07216c4725 /object.go
parent56e3d1b71945877f116b87e7462fa96f427b0ecd (diff)
parent126e4fe15a604227693deb0c443e25a27751ec93 (diff)
downloadgo-schwift-f9be896d5fd937c64a95797ced7ce887103518c8.tar.gz
Merge pull request #7 from databus23/patch-2
Cover more readers for automatic etag calculation
Diffstat (limited to 'object.go')
-rw-r--r--object.go11
1 files changed, 2 insertions, 9 deletions
diff --git a/object.go b/object.go
index 960a3a6..8669719 100644
--- a/object.go
+++ b/object.go
@@ -298,13 +298,6 @@ func tryComputeContentLength(content io.Reader) *uint64 {
return nil
}
-//This covers both bytes.Reader and strings.Reader in a way that is compatible
-//with earlier versions of Go that don't have strings.Reader yet.
-type likeBytesReader interface {
- io.WriterTo
- io.Seeker
-}
-
func tryComputeEtag(content io.Reader, headers ObjectHeaders) {
h := headers.Etag()
if h.Exists() {
@@ -319,11 +312,11 @@ func tryComputeEtag(content io.Reader, headers ObjectHeaders) {
//so this one is easy
sum := md5.Sum(r.Bytes())
h.Set(hex.EncodeToString(sum[:]))
- case likeBytesReader:
+ case io.ReadSeeker:
//bytes.Reader does not have such a method, but it is an io.Seeker, so we
//can read the entire thing and then seek back to where we started
hash := md5.New()
- n, _ := r.WriteTo(hash)
+ n, _ := io.Copy(hash, r)
r.Seek(-n, io.SeekCurrent)
h.Set(hex.EncodeToString(hash.Sum(nil)))
}