123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package minio
- import (
- "context"
- "io"
- "math"
- "os"
- "github.com/minio/minio-go/v7/pkg/s3utils"
- )
- func isObject(reader io.Reader) (ok bool) {
- _, ok = reader.(*Object)
- return
- }
- func isReadAt(reader io.Reader) (ok bool) {
- var v *os.File
- v, ok = reader.(*os.File)
- if ok {
-
-
-
-
- for _, f := range []string{
- "/dev/stdin",
- "/dev/stdout",
- "/dev/stderr",
- } {
- if f == v.Name() {
- ok = false
- break
- }
- }
- } else {
- _, ok = reader.(io.ReaderAt)
- }
- return
- }
- func OptimalPartInfo(objectSize int64, configuredPartSize uint64) (totalPartsCount int, partSize int64, lastPartSize int64, err error) {
-
- var unknownSize bool
- if objectSize == -1 {
- unknownSize = true
- objectSize = maxMultipartPutObjectSize
- }
-
- if objectSize > maxMultipartPutObjectSize {
- err = errEntityTooLarge(objectSize, maxMultipartPutObjectSize, "", "")
- return
- }
- var partSizeFlt float64
- if configuredPartSize > 0 {
- if int64(configuredPartSize) > objectSize {
- err = errEntityTooLarge(int64(configuredPartSize), objectSize, "", "")
- return
- }
- if !unknownSize {
- if objectSize > (int64(configuredPartSize) * maxPartsCount) {
- err = errInvalidArgument("Part size * max_parts(10000) is lesser than input objectSize.")
- return
- }
- }
- if configuredPartSize < absMinPartSize {
- err = errInvalidArgument("Input part size is smaller than allowed minimum of 5MiB.")
- return
- }
- if configuredPartSize > maxPartSize {
- err = errInvalidArgument("Input part size is bigger than allowed maximum of 5GiB.")
- return
- }
- partSizeFlt = float64(configuredPartSize)
- if unknownSize {
-
-
- objectSize = int64(configuredPartSize) * maxPartsCount
- }
- } else {
- configuredPartSize = minPartSize
-
-
- partSizeFlt = float64(objectSize / maxPartsCount)
- partSizeFlt = math.Ceil(partSizeFlt/float64(configuredPartSize)) * float64(configuredPartSize)
- }
-
- totalPartsCount = int(math.Ceil(float64(objectSize) / partSizeFlt))
-
- partSize = int64(partSizeFlt)
-
- lastPartSize = objectSize - int64(totalPartsCount-1)*partSize
- return totalPartsCount, partSize, lastPartSize, nil
- }
- func (c Client) newUploadID(ctx context.Context, bucketName, objectName string, opts PutObjectOptions) (uploadID string, err error) {
-
- if err := s3utils.CheckValidBucketName(bucketName); err != nil {
- return "", err
- }
- if err := s3utils.CheckValidObjectName(objectName); err != nil {
- return "", err
- }
-
- initMultipartUploadResult, err := c.initiateMultipartUpload(ctx, bucketName, objectName, opts)
- if err != nil {
- return "", err
- }
- return initMultipartUploadResult.UploadID, nil
- }
|