MCPcopy
hub / github.com/minio/minio-go / putObjectMultipartStreamOptionalChecksum

Method putObjectMultipartStreamOptionalChecksum

api-put-object-streaming.go:296–449  ·  view source on GitHub ↗
(ctx context.Context, bucketName, objectName string,
	reader io.Reader, size int64, opts PutObjectOptions,
)

Source from the content-addressed store, hash-verified

294}
295
296func (c *Client) putObjectMultipartStreamOptionalChecksum(ctx context.Context, bucketName, objectName string,
297 reader io.Reader, size int64, opts PutObjectOptions,
298) (info UploadInfo, err error) {
299 // Input validation.
300 if err = s3utils.CheckValidBucketName(bucketName); err != nil {
301 return UploadInfo{}, err
302 }
303 if err = s3utils.CheckValidObjectName(objectName); err != nil {
304 return UploadInfo{}, err
305 }
306
307 // Calculate the optimal parts info for a given size.
308 totalPartsCount, partSize, lastPartSize, err := OptimalPartInfo(size, opts.PartSize)
309 if err != nil {
310 return UploadInfo{}, err
311 }
312 // Initiates a new multipart request
313 uploadID, err := c.newUploadID(ctx, bucketName, objectName, opts)
314 if err != nil {
315 return UploadInfo{}, err
316 }
317
318 // Aborts the multipart upload if the function returns
319 // any error, since we do not resume we should purge
320 // the parts which have been uploaded to relinquish
321 // storage space.
322 defer func() {
323 if err != nil {
324 c.abortMultipartUpload(ctx, bucketName, objectName, uploadID)
325 }
326 }()
327
328 // Create checksums
329 // CRC32C is ~50% faster on AMD64 @ 30GB/s
330 customHeader := make(http.Header)
331 crc := opts.AutoChecksum.Hasher()
332 md5Hash := c.md5Hasher()
333 defer md5Hash.Close()
334
335 // Total data read and written to server. should be equal to 'size' at the end of the call.
336 var totalUploadedSize int64
337
338 // Initialize parts uploaded map.
339 partsInfo := make(map[int]ObjectPart)
340
341 // Create a buffer.
342 buf := make([]byte, partSize)
343
344 // Avoid declaring variables in the for loop
345 var md5Base64 string
346
347 // Part number always starts with '1'.
348 var partNumber int
349 for partNumber = 1; partNumber <= totalPartsCount; partNumber++ {
350 // Proceed to upload the part.
351 if partNumber == totalPartsCount {
352 partSize = lastPartSize
353 }

Callers 1

Calls 15

newUploadIDMethod · 0.95
abortMultipartUploadMethod · 0.95
uploadPartMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
OptimalPartInfoFunction · 0.85
newHookFunction · 0.85
errUnexpectedEOFFunction · 0.85
errInvalidArgumentFunction · 0.85
completedPartsTypeAlias · 0.85
applyAutoChecksumFunction · 0.85

Tested by

no test coverage detected