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

Method GetBytes

jetstream/object.go:1094–1106  ·  view source on GitHub ↗

GetBytes is a convenience function to pull an object from this object store and return it as a byte slice.

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

Source from the content-addressed store, hash-verified

1092
1093// GetBytes is a convenience function to pull an object from this object store and return it as a byte slice.
1094func (obs *obs) GetBytes(ctx context.Context, name string, opts ...GetObjectOpt) ([]byte, error) {
1095 result, err := obs.Get(ctx, name, opts...)
1096 if err != nil {
1097 return nil, err
1098 }
1099 defer result.Close()
1100
1101 var b bytes.Buffer
1102 if _, err := b.ReadFrom(result); err != nil {
1103 return nil, err
1104 }
1105 return b.Bytes(), nil
1106}
1107
1108// PutString is convenience function to put a string into this object store.
1109func (obs *obs) PutString(ctx context.Context, name string, data string) (*ObjectInfo, error) {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
BytesMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected