Open object file
(ctx context.Context, options ...fs.OpenOption)
| 325 | |
| 326 | // Open object file |
| 327 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) { |
| 328 | bucketName, bucketPath := o.split() |
| 329 | req := objectstorage.GetObjectRequest{ |
| 330 | NamespaceName: common.String(o.fs.opt.Namespace), |
| 331 | BucketName: common.String(bucketName), |
| 332 | ObjectName: common.String(bucketPath), |
| 333 | } |
| 334 | o.applyGetObjectOptions(&req, options...) |
| 335 | useBYOKGetObject(o.fs, &req) |
| 336 | var resp objectstorage.GetObjectResponse |
| 337 | err := o.fs.pacer.Call(func() (bool, error) { |
| 338 | var err error |
| 339 | resp, err = o.fs.srv.GetObject(ctx, req) |
| 340 | return shouldRetry(ctx, resp.HTTPResponse(), err) |
| 341 | }) |
| 342 | if err != nil { |
| 343 | return nil, err |
| 344 | } |
| 345 | // read size from ContentLength or ContentRange |
| 346 | bytes := resp.ContentLength |
| 347 | if resp.ContentRange != nil { |
| 348 | var contentRange = *resp.ContentRange |
| 349 | slash := strings.IndexRune(contentRange, '/') |
| 350 | if slash >= 0 { |
| 351 | i, err := strconv.ParseInt(contentRange[slash+1:], 10, 64) |
| 352 | if err == nil { |
| 353 | bytes = &i |
| 354 | } else { |
| 355 | fs.Debugf(o, "Failed to find parse integer from in %q: %v", contentRange, err) |
| 356 | } |
| 357 | } else { |
| 358 | fs.Debugf(o, "Failed to find length in %q", contentRange) |
| 359 | } |
| 360 | } |
| 361 | err = o.decodeMetaDataObject(&resp) |
| 362 | if err != nil { |
| 363 | return nil, err |
| 364 | } |
| 365 | o.bytes = *bytes |
| 366 | return resp.HTTPResponse().Body, nil |
| 367 | } |
| 368 | |
| 369 | func isZeroLength(streamReader io.Reader) bool { |
| 370 | switch v := streamReader.(type) { |
nothing calls this directly
no test coverage detected