Open is used to request a specific part of the file using fs.RangeOption
(ctx context.Context, options ...fs.OpenOption)
| 216 | |
| 217 | // Open is used to request a specific part of the file using fs.RangeOption |
| 218 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) { |
| 219 | var err error |
| 220 | |
| 221 | if o.Object == nil { |
| 222 | err = o.refreshFromSource(ctx, true) |
| 223 | } else { |
| 224 | err = o.refresh(ctx) |
| 225 | } |
| 226 | if err != nil { |
| 227 | return nil, err |
| 228 | } |
| 229 | |
| 230 | cacheReader := NewObjectHandle(ctx, o, o.CacheFs) |
| 231 | var offset, limit int64 = 0, -1 |
| 232 | for _, option := range options { |
| 233 | switch x := option.(type) { |
| 234 | case *fs.SeekOption: |
| 235 | offset = x.Offset |
| 236 | case *fs.RangeOption: |
| 237 | offset, limit = x.Decode(o.Size()) |
| 238 | } |
| 239 | _, err = cacheReader.Seek(offset, io.SeekStart) |
| 240 | if err != nil { |
| 241 | return nil, err |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return readers.NewLimitedReadCloser(cacheReader, limit), nil |
| 246 | } |
| 247 | |
| 248 | // Update will change the object data |
| 249 | func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error { |
nothing calls this directly
no test coverage detected