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

Method GetFile

object.go:894–912  ·  view source on GitHub ↗

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

(name, file string, opts ...GetObjectOpt)

Source from the content-addressed store, hash-verified

892
893// GetFile is a convenience function to pull and object and place in a file.
894func (obs *obs) GetFile(name, file string, opts ...GetObjectOpt) error {
895 // Expect file to be new.
896 f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE, 0600)
897 if err != nil {
898 return err
899 }
900 defer f.Close()
901
902 result, err := obs.Get(name, opts...)
903 if err != nil {
904 os.Remove(f.Name())
905 return err
906 }
907 defer result.Close()
908
909 // Stream copy to the file.
910 _, err = io.Copy(f, result)
911 return err
912}
913
914type GetObjectInfoOpt interface {
915 configureGetInfo(opts *getObjectInfoOpts) error

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
NameMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected