MCPcopy
hub / github.com/nats-io/nats.go / Get

Method Get

jetstream/object.go:836–953  ·  view source on GitHub ↗

Get will pull the object from the underlying stream.

(ctx context.Context, name string, opts ...GetObjectOpt)

Source from the content-addressed store, hash-verified

834
835// Get will pull the object from the underlying stream.
836func (obs *obs) Get(ctx context.Context, name string, opts ...GetObjectOpt) (ObjectResult, error) {
837 ctx, cancel := obs.js.wrapContextWithoutDeadline(ctx)
838 var o getObjectOpts
839 for _, opt := range opts {
840 if opt != nil {
841 if err := opt(&o); err != nil {
842 return nil, err
843 }
844 }
845 }
846 infoOpts := make([]GetObjectInfoOpt, 0)
847 if o.showDeleted {
848 infoOpts = append(infoOpts, GetObjectInfoShowDeleted())
849 }
850
851 // Grab meta info.
852 info, err := obs.GetInfo(ctx, name, infoOpts...)
853 if err != nil {
854 return nil, err
855 }
856 if info.NUID == "" {
857 return nil, ErrBadObjectMeta
858 }
859
860 // Check for object links. If single objects we do a pass through.
861 if info.isLink() {
862 if info.ObjectMeta.Opts.Link.Name == "" {
863 return nil, ErrCantGetBucket
864 }
865
866 // is the link in the same bucket?
867 lbuck := info.ObjectMeta.Opts.Link.Bucket
868 if lbuck == obs.name {
869 return obs.Get(ctx, info.ObjectMeta.Opts.Link.Name)
870 }
871
872 // different bucket
873 lobs, err := obs.js.ObjectStore(ctx, lbuck)
874 if err != nil {
875 return nil, err
876 }
877 return lobs.Get(ctx, info.ObjectMeta.Opts.Link.Name)
878 }
879
880 result := &objResult{info: info, ctx: ctx, cancel: cancel}
881 if info.Size == 0 {
882 return result, nil
883 }
884
885 pr, pw := net.Pipe()
886 result.r = pr
887
888 gotErr := func(m *nats.Msg, err error) {
889 pw.Close()
890 m.Sub.Unsubscribe()
891 result.setErr(err)
892 }
893

Callers 3

GetBytesMethod · 0.95
GetStringMethod · 0.95
GetFileMethod · 0.95

Calls 15

GetInfoMethod · 0.95
setErrMethod · 0.95
GetMetadataFieldsFunction · 0.92
UnsubscribeMethod · 0.80
GetObjectInfoShowDeletedFunction · 0.70
ObjectStoreMethod · 0.65
GetMethod · 0.65
DoneMethod · 0.65
ErrMethod · 0.65
OrderedConsumerMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected