calculateEvenSplits - computes splits for a source and returns start and end index slices. Splits happen evenly to be sure that no part is less than 5MiB, as that could fail the multipart request if it is not the last part. If partSize is 0, defaults to maxPartSize (5 GiB).
(size int64, src CopySrcOptions, partSize int64)
| 589 | // part is less than 5MiB, as that could fail the multipart request if |
| 590 | // it is not the last part. If partSize is 0, defaults to maxPartSize (5 GiB). |
| 591 | func calculateEvenSplits(size int64, src CopySrcOptions, partSize int64) (startIndex, endIndex []int64) { |
| 592 | if size == 0 { |
| 593 | return startIndex, endIndex |
| 594 | } |
| 595 | |
| 596 | reqParts := partsRequired(size, partSize) |
| 597 | startIndex = make([]int64, reqParts) |
| 598 | endIndex = make([]int64, reqParts) |
| 599 | // Compute number of required parts `k`, as: |
| 600 | // |
| 601 | // k = ceiling(size / copyPartSize) |
| 602 | // |
| 603 | // Now, distribute the `size` bytes in the source into |
| 604 | // k parts as evenly as possible: |
| 605 | // |
| 606 | // r parts sized (q+1) bytes, and |
| 607 | // (k - r) parts sized q bytes, where |
| 608 | // |
| 609 | // size = q * k + r (by simple division of size by k, |
| 610 | // so that 0 <= r < k) |
| 611 | // |
| 612 | start := src.Start |
| 613 | if start == -1 { |
| 614 | start = 0 |
| 615 | } |
| 616 | quot, rem := size/reqParts, size%reqParts |
| 617 | nextStart := start |
| 618 | for j := int64(0); j < reqParts; j++ { |
| 619 | curPartSize := quot |
| 620 | if j < rem { |
| 621 | curPartSize++ |
| 622 | } |
| 623 | |
| 624 | cStart := nextStart |
| 625 | cEnd := cStart + curPartSize - 1 |
| 626 | nextStart = cEnd + 1 |
| 627 | |
| 628 | startIndex[j], endIndex[j] = cStart, cEnd |
| 629 | } |
| 630 | return startIndex, endIndex |
| 631 | } |