Skip to content

Commit

Permalink
Add GetObject convenience wrapper using GetPartialObject
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Jun 11, 2015
1 parent 7ece991 commit 03b6580
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type BucketAPI interface {

// ObjectAPI - object specific Read/Write/Stat interface
type ObjectAPI interface {
GetObject(bucket, object string) (io.ReadCloser, ObjectStat, error)
GetPartialObject(bucket, object string, offset, length int64) (io.ReadCloser, ObjectStat, error)
PutObject(bucket, object string, size int64, data io.Reader) error
StatObject(bucket, object string) (ObjectStat, error)
Expand Down Expand Up @@ -181,13 +182,21 @@ func New(config Config) (API, error) {

/// Object operations

// GetPartialObject retrieve object
// GetObject retrieve object

// Downloads full object with no ranges, if you need ranges use GetPartialObject
func (a api) GetObject(bucket, object string) (io.ReadCloser, ObjectStat, error) {
// get object
return a.getPartialObject(bucket, object, 0, 0)
}

// GetPartialObject retrieve partial object
//
// Takes range arguments to download the specified range bytes of an object.
// Setting offset and length = 0 will download the full object.
// For more information about the HTTP Range header, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
func (a api) GetPartialObject(bucket, object string, offset, length int64) (io.ReadCloser, ObjectStat, error) {
// get the the object
// get partial object
return a.getPartialObject(bucket, object, offset, length)
}

Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestObjectOperations(t *testing.T) {
t.Fatalf("Error")
}

reader, metadata, err := a.GetPartialObject("bucket", "object", 0, 0)
reader, metadata, err := a.GetObject("bucket", "object")
if err != nil {
t.Fatalf("Error")
}
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/getobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
reader, stat, err := s3Client.GetPartialObject("mybucket", "myobject", 0, 0)
reader, stat, err := s3Client.GetObject("mybucket", "myobject")
if err != nil {
log.Fatalln(err)
}
Expand Down

0 comments on commit 03b6580

Please sign in to comment.