WriteAll is a shortcut for creating a Writer via NewWriter and writing p. If opts.ContentMD5 is not set, WriteAll will compute the MD5 of p and use it as the ContentMD5 option for the Writer it creates. Using Upload may be more efficient.
(ctx context.Context, key string, p []byte, opts *WriterOptions)
| 1092 | // |
| 1093 | // Using Upload may be more efficient. |
| 1094 | func (b *Bucket) WriteAll(ctx context.Context, key string, p []byte, opts *WriterOptions) (err error) { |
| 1095 | realOpts := new(WriterOptions) |
| 1096 | if opts != nil { |
| 1097 | *realOpts = *opts |
| 1098 | } |
| 1099 | if len(realOpts.ContentMD5) == 0 { |
| 1100 | sum := md5.Sum(p) |
| 1101 | realOpts.ContentMD5 = sum[:] |
| 1102 | } |
| 1103 | w, err := b.NewWriter(ctx, key, realOpts) |
| 1104 | if err != nil { |
| 1105 | return err |
| 1106 | } |
| 1107 | if _, err := w.Write(p); err != nil { |
| 1108 | _ = w.Close() |
| 1109 | return err |
| 1110 | } |
| 1111 | return w.Close() |
| 1112 | } |
| 1113 | |
| 1114 | // Upload reads from an io.Reader r and writes into a blob. |
| 1115 | // |