Convert writers to Blocking readers
This commit is contained in:
+31
-10
@@ -37,7 +37,7 @@ type API interface {
|
||||
|
||||
// BucketAPI - bucket specific Read/Write/Stat interface
|
||||
type BucketAPI interface {
|
||||
CreateBucket(bucket, acl, location string) error
|
||||
MakeBucket(bucket, acl, location string) error
|
||||
SetBucketACL(bucket, acl string) error
|
||||
StatBucket(bucket string) error
|
||||
DeleteBucket(bucket string) error
|
||||
@@ -49,11 +49,18 @@ type BucketAPI interface {
|
||||
// ObjectAPI - object specific Read/Write/Stat interface
|
||||
type ObjectAPI interface {
|
||||
GetObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectMetadata, error)
|
||||
CreateObject(bucket, object string, size uint64, data io.Reader) (string, error)
|
||||
PutObject(bucket, object string, size uint64, data io.Reader) (string, error)
|
||||
StatObject(bucket, object string) (*ObjectMetadata, error)
|
||||
DeleteObject(bucket, object string) error
|
||||
}
|
||||
|
||||
// MultipartManagementAPI - multi parts management API
|
||||
type MultiPartManagementAPI interface {
|
||||
MultipartAbort(bucket, object, uploadID string) error
|
||||
MultipartAbortRecursive(bucket, object string) <-chan error
|
||||
ListParts(bucket, prefix string, recursive bool) <-chan PartsOnChannel
|
||||
}
|
||||
|
||||
// BucketOnChannel - bucket metadata over read channel
|
||||
type BucketOnChannel struct {
|
||||
Data *BucketMetadata
|
||||
@@ -66,6 +73,20 @@ type ObjectOnChannel struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// PartsOnChannel - part metadata over read channel
|
||||
type PartsOnChannel struct {
|
||||
Data *PartMetadata
|
||||
Err error
|
||||
}
|
||||
|
||||
// PartMetadata container for particular part of an object
|
||||
type PartMetadata struct {
|
||||
PartNumber int
|
||||
LastModified time.Time
|
||||
ETag string
|
||||
Size int64
|
||||
}
|
||||
|
||||
// BucketMetadata container for bucket metadata
|
||||
type BucketMetadata struct {
|
||||
// The name of the bucket.
|
||||
@@ -211,14 +232,14 @@ func (a *api) newObjectUpload(bucket, object string, data io.Reader) (string, er
|
||||
}
|
||||
completePart, err := a.uploadPart(bucket, object, uploadID, part.Num, part.Len, part.Data)
|
||||
if err != nil {
|
||||
return "", a.abortMultipartUpload(bucket, object, uploadID)
|
||||
return "", err
|
||||
}
|
||||
completeMultipartUpload.Part = append(completeMultipartUpload.Part, completePart)
|
||||
}
|
||||
sort.Sort(completedParts(completeMultipartUpload.Part))
|
||||
completeMultipartUploadResult, err := a.completeMultipartUpload(bucket, object, uploadID, completeMultipartUpload)
|
||||
if err != nil {
|
||||
return "", a.abortMultipartUpload(bucket, object, uploadID)
|
||||
return "", err
|
||||
}
|
||||
return completeMultipartUploadResult.ETag, nil
|
||||
}
|
||||
@@ -243,24 +264,24 @@ func (a *api) continueObjectUpload(bucket, object, uploadID string, data io.Read
|
||||
}
|
||||
completedPart, err := a.uploadPart(bucket, object, uploadID, part.Num, part.Len, part.Data)
|
||||
if err != nil {
|
||||
return "", a.abortMultipartUpload(bucket, object, uploadID)
|
||||
return "", err
|
||||
}
|
||||
completeMultipartUpload.Part = append(completeMultipartUpload.Part, completedPart)
|
||||
}
|
||||
sort.Sort(completedParts(completeMultipartUpload.Part))
|
||||
completeMultipartUploadResult, err := a.completeMultipartUpload(bucket, object, uploadID, completeMultipartUpload)
|
||||
if err != nil {
|
||||
return "", a.abortMultipartUpload(bucket, object, uploadID)
|
||||
return "", err
|
||||
}
|
||||
return completeMultipartUploadResult.ETag, nil
|
||||
}
|
||||
|
||||
// CreateObject create an object in a bucket
|
||||
// PutObject create an object in a bucket
|
||||
//
|
||||
// You must have WRITE permissions on a bucket to create an object
|
||||
//
|
||||
// This version of CreateObject automatically does multipart for more than 5MB worth of data
|
||||
func (a *api) CreateObject(bucket, object string, size uint64, data io.Reader) (string, error) {
|
||||
func (a *api) PutObject(bucket, object string, size uint64, data io.Reader) (string, error) {
|
||||
if strings.TrimSpace(object) == "" {
|
||||
return "", errors.New("object name cannot be empty")
|
||||
}
|
||||
@@ -310,7 +331,7 @@ func (a *api) DeleteObject(bucket, object string) error {
|
||||
|
||||
/// Bucket operations
|
||||
|
||||
// CreateBucket create a new bucket
|
||||
// MakeBucket make a new bucket
|
||||
//
|
||||
// optional arguments are acl and location - by default all buckets are created
|
||||
// with ``private`` acl and location set to US Standard if one wishes to set
|
||||
@@ -327,7 +348,7 @@ func (a *api) DeleteObject(bucket, object string) error {
|
||||
// ------------------
|
||||
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
|
||||
// Default - US standard
|
||||
func (a *api) CreateBucket(bucket, acl, location string) error {
|
||||
func (a *api) MakeBucket(bucket, acl, location string) error {
|
||||
return a.putBucket(bucket, acl, location)
|
||||
}
|
||||
|
||||
|
||||
+1
-9
@@ -98,14 +98,6 @@ type initiator struct {
|
||||
DisplayName string
|
||||
}
|
||||
|
||||
// part container for particular part of an object
|
||||
type part struct {
|
||||
PartNumber int
|
||||
LastModified time.Time `type:"timestamp" timestampFormat:"iso8601"`
|
||||
ETag string
|
||||
Size int64
|
||||
}
|
||||
|
||||
// listObjectPartsResult container for ListObjectParts response
|
||||
type listObjectPartsResult struct {
|
||||
Bucket string
|
||||
@@ -122,7 +114,7 @@ type listObjectPartsResult struct {
|
||||
|
||||
// Indicates whether the returned list of parts is truncated.
|
||||
IsTruncated bool
|
||||
Part []*part
|
||||
Part []*PartMetadata
|
||||
|
||||
EncodingType string
|
||||
}
|
||||
|
||||
Generated
Vendored
+10
-5
@@ -62,6 +62,7 @@ func (a *lowLevelAPI) listMultipartUploads(bucket, keymarker, uploadIDMarker, pr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
@@ -75,7 +76,7 @@ func (a *lowLevelAPI) listMultipartUploads(bucket, keymarker, uploadIDMarker, pr
|
||||
}
|
||||
|
||||
// close body while returning, along with any error
|
||||
return listMultipartUploadsResult, resp.Body.Close()
|
||||
return listMultipartUploadsResult, nil
|
||||
}
|
||||
|
||||
// initiateMultipartRequest wrapper creates a new initiateMultiPart request
|
||||
@@ -98,6 +99,7 @@ func (a *lowLevelAPI) initiateMultipartUpload(bucket, object string) (*initiateM
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
@@ -109,7 +111,7 @@ func (a *lowLevelAPI) initiateMultipartUpload(bucket, object string) (*initiateM
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return initiateMultipartUploadResult, resp.Body.Close()
|
||||
return initiateMultipartUploadResult, nil
|
||||
}
|
||||
|
||||
// completeMultipartUploadRequest wrapper creates a new CompleteMultipartUpload request
|
||||
@@ -142,6 +144,7 @@ func (a *lowLevelAPI) completeMultipartUpload(bucket, object, uploadID string, c
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
@@ -153,7 +156,7 @@ func (a *lowLevelAPI) completeMultipartUpload(bucket, object, uploadID string, c
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return completeMultipartUploadResult, resp.Body.Close()
|
||||
return completeMultipartUploadResult, nil
|
||||
}
|
||||
|
||||
// abortMultipartUploadRequest wrapper creates a new AbortMultipartUpload request
|
||||
@@ -219,6 +222,7 @@ func (a *lowLevelAPI) listObjectParts(bucket, object, uploadID string, partNumbe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
@@ -230,7 +234,7 @@ func (a *lowLevelAPI) listObjectParts(bucket, object, uploadID string, partNumbe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return listObjectPartsResult, resp.Body.Close()
|
||||
return listObjectPartsResult, nil
|
||||
}
|
||||
|
||||
// uploadPartRequest wrapper creates a new UploadPart request
|
||||
@@ -274,10 +278,11 @@ func (a *lowLevelAPI) uploadPart(bucket, object, uploadID string, partNumber int
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
}
|
||||
}
|
||||
return completePart, resp.Body.Close()
|
||||
return completePart, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user