Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit e6e8c65

Browse files
committed
copy content to hash while writing to new buffer
1 parent 046c882 commit e6e8c65

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

openstack/objectstorage/v1/objects/requests.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,16 @@ func Create(c *gophercloud.ServiceClient, containerName, objectName string, cont
212212
url += query
213213
}
214214

215-
var contentBuffer *bytes.Buffer
216-
contentReader := io.TeeReader(content, contentBuffer)
217-
218215
hash := md5.New()
219-
io.Copy(hash, contentReader)
220-
localChecksum := hash.Sum(nil)
221-
fmt.Printf("localChecksum: %s", fmt.Sprintf("%x", localChecksum))
222216

217+
contentBuffer := bytes.NewBuffer([]byte{})
218+
_, err := io.Copy(contentBuffer, io.TeeReader(content, hash))
219+
if err != nil {
220+
res.Err = err
221+
return res
222+
}
223+
224+
localChecksum := hash.Sum(nil)
223225
h["ETag"] = fmt.Sprintf("%x", localChecksum)
224226

225227
ropts := gophercloud.RequestOpts{
@@ -232,7 +234,6 @@ func Create(c *gophercloud.ServiceClient, containerName, objectName string, cont
232234
if resp != nil {
233235
res.Header = resp.Header
234236
}
235-
fmt.Printf("ETag: %s", resp.Header.Get("ETag"))
236237
if resp.Header.Get("ETag") == fmt.Sprintf("%x", localChecksum) {
237238
res.Err = err
238239
break

0 commit comments

Comments
 (0)