Merge pull request #424 from fkautz/pr_out_add_partial_object_support_to_donut_driver

This commit is contained in:
Frederick F. Kautz IV 2015-04-01 15:48:27 -07:00
commit e73c3b379f
2 changed files with 27 additions and 1 deletions

View File

@ -33,6 +33,7 @@ import (
"github.com/minio-io/minio/pkg/api"
"github.com/minio-io/minio/pkg/drivers"
"github.com/minio-io/minio/pkg/drivers/donut"
"github.com/minio-io/minio/pkg/drivers/file"
"github.com/minio-io/minio/pkg/drivers/memory"
"github.com/minio-io/minio/pkg/drivers/mocks"
@ -71,6 +72,14 @@ var _ = Suite(&MySuite{
},
})
var _ = Suite(&MySuite{
initDriver: func() (drivers.Driver, string) {
root, _ := ioutil.TempDir(os.TempDir(), "minio-api")
_, _, driver := donut.Start(root)
return driver, root
},
})
func (s *MySuite) SetUpSuite(c *C) {
driver, root := s.initDriver()
if root != "" {

View File

@ -28,6 +28,7 @@ import (
"github.com/minio-io/minio/pkg/drivers"
"github.com/minio-io/minio/pkg/storage/donut"
"github.com/minio-io/minio/pkg/utils/log"
"io/ioutil"
)
// donutDriver - creates a new single disk drivers driver using donut
@ -112,7 +113,23 @@ func (d donutDriver) GetObject(target io.Writer, bucket, key string) (int64, err
// GetPartialObject retrieves an object range and writes it to a writer
func (d donutDriver) GetPartialObject(w io.Writer, bucket, object string, start, length int64) (int64, error) {
return 0, errors.New("Not Implemented")
// TODO more efficient get partial object with proper donut support
errParams := map[string]string{
"bucket": bucket,
"object": object,
"start": strconv.FormatInt(start, 10),
"length": strconv.FormatInt(length, 10),
}
reader, err := d.donut.GetObjectReader(bucket, object)
if err != nil {
return 0, iodine.New(err, errParams)
}
_, err = io.CopyN(ioutil.Discard, reader, start)
if err != nil {
return 0, iodine.New(err, errParams)
}
n, err := io.CopyN(w, reader, length)
return n, iodine.New(err, errParams)
}
// GetObjectMetadata retrieves an object's metadata