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

Method GetFile

jetstream/object.go:1139–1157  ·  view source on GitHub ↗

GetFile is a convenience function to pull and object and place in a file.

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

Source from the content-addressed store, hash-verified

1137
1138// GetFile is a convenience function to pull and object and place in a file.
1139func (obs *obs) GetFile(ctx context.Context, name, file string, opts ...GetObjectOpt) error {
1140 // Expect file to be new.
1141 f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE, 0600)
1142 if err != nil {
1143 return err
1144 }
1145 defer f.Close()
1146
1147 result, err := obs.Get(ctx, name, opts...)
1148 if err != nil {
1149 os.Remove(f.Name())
1150 return err
1151 }
1152 defer result.Close()
1153
1154 // Stream copy to the file.
1155 _, err = io.Copy(f, result)
1156 return err
1157}
1158
1159// GetInfo will retrieve the current information for the object.
1160func (obs *obs) GetInfo(ctx context.Context, name string, opts ...GetObjectInfoOpt) (*ObjectInfo, error) {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
NameMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected