Copy the blob stored at srcKey to dstKey. A nil CopyOptions is treated the same as the zero value. If the source blob does not exist, Copy returns an error for which gcerrors.Code will return gcerrors.NotFound. If the destination blob already exists, it is overwritten.
(ctx context.Context, dstKey, srcKey string, opts *CopyOptions)
| 1249 | // |
| 1250 | // If the destination blob already exists, it is overwritten. |
| 1251 | func (b *Bucket) Copy(ctx context.Context, dstKey, srcKey string, opts *CopyOptions) (err error) { |
| 1252 | if !utf8.ValidString(srcKey) { |
| 1253 | return gcerr.Newf(gcerr.InvalidArgument, nil, "blob: Copy srcKey must be a valid UTF-8 string: %q", srcKey) |
| 1254 | } |
| 1255 | if !utf8.ValidString(dstKey) { |
| 1256 | return gcerr.Newf(gcerr.InvalidArgument, nil, "blob: Copy dstKey must be a valid UTF-8 string: %q", dstKey) |
| 1257 | } |
| 1258 | if opts == nil { |
| 1259 | opts = &CopyOptions{} |
| 1260 | } |
| 1261 | dopts := &driver.CopyOptions{ |
| 1262 | BeforeCopy: opts.BeforeCopy, |
| 1263 | } |
| 1264 | b.mu.RLock() |
| 1265 | defer b.mu.RUnlock() |
| 1266 | if b.closed { |
| 1267 | return errClosed |
| 1268 | } |
| 1269 | ctx, span := b.tracer.Start(ctx, "Copy") |
| 1270 | defer func() { b.tracer.End(ctx, span, err) }() |
| 1271 | return wrapError(b.b, b.b.Copy(ctx, dstKey, srcKey, dopts), fmt.Sprintf("%s -> %s", srcKey, dstKey)) |
| 1272 | } |
| 1273 | |
| 1274 | // Delete deletes the blob stored at key. |
| 1275 | // |