2011-04-04 02:59:46 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
2011-04-04 22:15:09 +00:00
|
|
|
"bytes"
|
|
|
|
"crypto/md5"
|
2011-04-04 02:59:46 +00:00
|
|
|
"io"
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
"camlistore.org/pkg/blob"
|
2011-04-04 02:59:46 +00:00
|
|
|
)
|
|
|
|
|
2013-09-01 16:12:17 +00:00
|
|
|
func (sto *s3Storage) ReceiveBlob(b blob.Ref, source io.Reader) (sr blob.SizedRef, err error) {
|
2014-03-17 02:39:43 +00:00
|
|
|
var buf bytes.Buffer
|
|
|
|
md5h := md5.New()
|
2011-04-04 22:15:09 +00:00
|
|
|
|
2014-03-17 02:39:43 +00:00
|
|
|
size, err := io.Copy(io.MultiWriter(&buf, md5h), source)
|
2011-04-04 22:15:09 +00:00
|
|
|
if err != nil {
|
2013-09-01 16:12:17 +00:00
|
|
|
return sr, err
|
2011-04-04 22:15:09 +00:00
|
|
|
}
|
2014-03-05 16:23:42 +00:00
|
|
|
|
2014-03-17 02:39:43 +00:00
|
|
|
if faultReceive.FailErr(&err) {
|
|
|
|
return
|
2014-03-05 16:23:42 +00:00
|
|
|
}
|
|
|
|
|
2014-03-17 02:39:43 +00:00
|
|
|
err = sto.s3Client.PutObject(b.String(), sto.bucket, md5h, size, &buf)
|
2011-04-04 22:15:09 +00:00
|
|
|
if err != nil {
|
2013-09-01 16:12:17 +00:00
|
|
|
return sr, err
|
2011-04-04 22:15:09 +00:00
|
|
|
}
|
2014-01-28 20:46:52 +00:00
|
|
|
return blob.SizedRef{Ref: b, Size: uint32(size)}, nil
|
2011-04-04 02:59:46 +00:00
|
|
|
}
|