NewObject creates a new in-memory Object corresponding to a CSUP object residing in storage. The CSUP header and metadata section are read and the metadata is deserialized so that vectors can be loaded into the cache on demand only as needed and retained in memory for future use.
(ctx context.Context, engine storage.Engine, uri *storage.URI)
| 26 | // the metadata is deserialized so that vectors can be loaded into the cache |
| 27 | // on demand only as needed and retained in memory for future use. |
| 28 | func NewObject(ctx context.Context, engine storage.Engine, uri *storage.URI) (*Object, error) { |
| 29 | // XXX currently we open a storage.Reader for every object and never close it. |
| 30 | // We should either close after a timeout and reopen when needed or change the |
| 31 | // storage API to have a more reasonable semantics around the Put/Get not leaving |
| 32 | // a file descriptor open for every long Get. Perhaps there should be another |
| 33 | // method for intermittent random access. |
| 34 | // XXX maybe open the reader inside Fetch if needed? |
| 35 | reader, err := engine.Get(ctx, uri) |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | object, err := csup.NewObject(reader) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | return NewObjectFromCSUP(object), nil |
| 44 | } |
| 45 | |
| 46 | func NewObjectFromCSUP(object *csup.Object) *Object { |
| 47 | return &Object{object: object} |
no test coverage detected