|
|
@ -10,16 +10,27 @@ type Storage struct { |
|
|
|
data map[string][]byte |
|
|
|
data map[string][]byte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error { |
|
|
|
type GenericError struct { |
|
|
|
|
|
|
|
bucket string |
|
|
|
|
|
|
|
path string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ObjectNotFound GenericError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (self ObjectNotFound) Error() string { |
|
|
|
|
|
|
|
return "Not Found: " + self.bucket + "#" + self.path |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error) { |
|
|
|
// TODO synchronize access
|
|
|
|
// TODO synchronize access
|
|
|
|
// get object
|
|
|
|
// get object
|
|
|
|
key := bucket + ":" + object |
|
|
|
key := bucket + ":" + object |
|
|
|
if val, ok := storage.data[key]; ok { |
|
|
|
if val, ok := storage.data[key]; ok { |
|
|
|
objectBuffer := bytes.NewBuffer(val) |
|
|
|
objectBuffer := bytes.NewBuffer(val) |
|
|
|
_, err := io.Copy(w, objectBuffer) |
|
|
|
written, err := io.Copy(w, objectBuffer) |
|
|
|
return err |
|
|
|
return written, err |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return errors.New("Not Found") |
|
|
|
return 0, ObjectNotFound{bucket: bucket, path: object} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|