GetFile is a convenience function to pull and object and place in a file.
(ctx context.Context, name, file string, opts ...GetObjectOpt)
| 1137 | |
| 1138 | // GetFile is a convenience function to pull and object and place in a file. |
| 1139 | func (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. |
| 1160 | func (obs *obs) GetInfo(ctx context.Context, name string, opts ...GetObjectInfoOpt) (*ObjectInfo, error) { |