Figure out the size of the contents. If the size was provided, trust it.
()
| 236 | // Figure out the size of the contents. |
| 237 | // If the size was provided, trust it. |
| 238 | func (h *UploadHandle) readerAndSize() (io.Reader, int64, error) { |
| 239 | if h.Size > 0 { |
| 240 | return h.Contents, int64(h.Size), nil |
| 241 | } |
| 242 | var b bytes.Buffer |
| 243 | n, err := io.Copy(&b, h.Contents) |
| 244 | if err != nil { |
| 245 | return nil, 0, err |
| 246 | } |
| 247 | return &b, n, nil |
| 248 | } |
| 249 | |
| 250 | // Upload uploads a blob, as described by the provided UploadHandle parameters. |
| 251 | func (c *Client) Upload(ctx context.Context, h *UploadHandle) (*PutResult, error) { |