Get will pull the object from the underlying stream.
(name string, opts ...GetObjectOpt)
| 587 | |
| 588 | // Get will pull the object from the underlying stream. |
| 589 | func (obs *obs) Get(name string, opts ...GetObjectOpt) (ObjectResult, error) { |
| 590 | var o getObjectOpts |
| 591 | for _, opt := range opts { |
| 592 | if opt != nil { |
| 593 | if err := opt.configureGetObject(&o); err != nil { |
| 594 | return nil, err |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | ctx := o.ctx |
| 599 | infoOpts := make([]GetObjectInfoOpt, 0) |
| 600 | if ctx != nil { |
| 601 | infoOpts = append(infoOpts, Context(ctx)) |
| 602 | } |
| 603 | if o.showDeleted { |
| 604 | infoOpts = append(infoOpts, GetObjectInfoShowDeleted()) |
| 605 | } |
| 606 | |
| 607 | // Grab meta info. |
| 608 | info, err := obs.GetInfo(name, infoOpts...) |
| 609 | if err != nil { |
| 610 | return nil, err |
| 611 | } |
| 612 | if info.NUID == _EMPTY_ { |
| 613 | return nil, ErrBadObjectMeta |
| 614 | } |
| 615 | |
| 616 | // Check for object links. If single objects we do a pass through. |
| 617 | if info.isLink() { |
| 618 | if info.ObjectMeta.Opts.Link.Name == _EMPTY_ { |
| 619 | return nil, ErrCantGetBucket |
| 620 | } |
| 621 | |
| 622 | // is the link in the same bucket? |
| 623 | lbuck := info.ObjectMeta.Opts.Link.Bucket |
| 624 | if lbuck == obs.name { |
| 625 | return obs.Get(info.ObjectMeta.Opts.Link.Name) |
| 626 | } |
| 627 | |
| 628 | // different bucket |
| 629 | lobs, err := obs.js.ObjectStore(lbuck) |
| 630 | if err != nil { |
| 631 | return nil, err |
| 632 | } |
| 633 | return lobs.Get(info.ObjectMeta.Opts.Link.Name) |
| 634 | } |
| 635 | |
| 636 | result := &objResult{info: info, ctx: ctx, readTimeout: obs.js.opts.wait} |
| 637 | if info.Size == 0 { |
| 638 | return result, nil |
| 639 | } |
| 640 | |
| 641 | pr, pw := net.Pipe() |
| 642 | result.r = pr |
| 643 | |
| 644 | gotErr := func(m *Msg, err error) { |
| 645 | pw.Close() |
| 646 | m.Sub.Unsubscribe() |
no test coverage detected