Skip to content

Commit

Permalink
ReadSeeker and usrMaxSize enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rem7 committed Mar 12, 2024
1 parent b9ecb3b commit a4489d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func putObjectMPU(ctx context.Context, svc *s3.Client, bucket, key string, data
Bucket: &bucket,
Key: &key,
PartNumber: aws.Int32(partNum),
Body: bytes.NewReader(data),
Body: io.ReadSeeker(bytes.NewReader(data)),
}
uploadPart, err := svc.UploadPart(ctx, uploadPartInput)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/s3"
"io"
"path/filepath"
"time"

Expand Down Expand Up @@ -86,7 +87,7 @@ func (r *RecursiveConcat) uploadPart(object *S3Obj, uploadId string, bucket, key
Key: &key,
PartNumber: aws.Int32(partNum),
UploadId: &uploadId,
Body: bytes.NewReader(object.Data),
Body: io.ReadSeeker(bytes.NewReader(object.Data)),
}

res, err := r.Client.UploadPart(context.TODO(), input)
Expand Down
4 changes: 3 additions & 1 deletion mem_concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ func uploadObject(ctx context.Context, client *s3.Client, bucket, key string, da
}
func uploadPart(ctx context.Context, client *s3.Client, uploadId, bucket, key string, data []byte, partNum *int32) (*s3.UploadPartOutput, error) {

body := io.ReadSeeker(bytes.NewReader(data))

rc, err := client.UploadPart(ctx, &s3.UploadPartInput{
UploadId: &uploadId,
Bucket: &bucket,
Key: &key,
PartNumber: partNum,
Body: bytes.NewReader(data),
Body: body,
ChecksumAlgorithm: types.ChecksumAlgorithmSha256,
})

Expand Down
7 changes: 6 additions & 1 deletion s3tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/s3"
"io"
"log"
"path/filepath"
"sort"
Expand Down Expand Up @@ -606,6 +607,10 @@ func findMinimumPartSize(finalSizeBytes, userMaxSize int64) int64 {
const fiveMB = beginningPad
partSize := int64(fiveMB)

if userMaxSize > 0 {
partSize = userMaxSize * 1024 * 1024
}

for ; partSize <= partSizeMax; partSize = partSize + fiveMB {
if finalSizeBytes/int64(partSize) < maxPartNumLimit {
break
Expand Down Expand Up @@ -703,7 +708,7 @@ func concatObjects(ctx context.Context, client *s3.Client, trimFirstBytes int, o
Key: &key,
PartNumber: &partNum,
UploadId: &uploadId,
Body: bytes.NewReader(object.Data),
Body: io.ReadSeeker(bytes.NewReader(object.Data)),
}
swg.Add()
go func(input *s3.UploadPartInput) {
Expand Down

0 comments on commit a4489d4

Please sign in to comment.