Skip to content

Commit

Permalink
recommit transfer manager v2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianyi Wang committed Oct 31, 2024
1 parent afdb785 commit 734b574
Show file tree
Hide file tree
Showing 13 changed files with 2,776 additions and 0 deletions.
16 changes: 16 additions & 0 deletions feature/s3/transfermanager/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package transfermanager

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/s3"
)

// S3APIClient defines an interface doing S3 client side operations for transfer manager
type S3APIClient interface {
PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)
UploadPart(context.Context, *s3.UploadPartInput, ...func(*s3.Options)) (*s3.UploadPartOutput, error)
CreateMultipartUpload(context.Context, *s3.CreateMultipartUploadInput, ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error)
CompleteMultipartUpload(context.Context, *s3.CompleteMultipartUploadInput, ...func(*s3.Options)) (*s3.CompleteMultipartUploadOutput, error)
AbortMultipartUpload(context.Context, *s3.AbortMultipartUploadInput, ...func(*s3.Options)) (*s3.AbortMultipartUploadOutput, error)
}
51 changes: 51 additions & 0 deletions feature/s3/transfermanager/api_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package transfermanager

import (
"github.com/aws/aws-sdk-go-v2/aws"
)

const userAgentKey = "s3-transfer"

// defaultMaxUploadParts is the maximum allowed number of parts in a multi-part upload
// on Amazon S3.
const defaultMaxUploadParts = 10000

// defaultPartSizeBytes is the default part size when transferring objects to/from S3
const minPartSizeBytes = 1024 * 1024 * 8

// defaultMultipartUploadThreshold is the default size threshold in bytes indicating when to use multipart upload.
const defaultMultipartUploadThreshold = 1024 * 1024 * 16

// defaultTransferConcurrency is the default number of goroutines to spin up when
// using PutObject().
const defaultTransferConcurrency = 5

// Client provides the API client to make operations call for Amazon Simple
// Storage Service's Transfer Manager
// It is safe to call Client methods concurrently across goroutines.
type Client struct {
options Options
}

// New returns an initialized Client from the client Options. Provide
// more functional options to further configure the Client
func New(s3Client S3APIClient, opts Options, optFns ...func(*Options)) *Client {
opts.S3 = s3Client
for _, fn := range optFns {
fn(&opts)
}

resolveConcurrency(&opts)
resolvePartSizeBytes(&opts)
resolveChecksumAlgorithm(&opts)
resolveMultipartUploadThreshold(&opts)

return &Client{
options: opts,
}
}

// NewFromConfig returns a new Client from the provided s3 config
func NewFromConfig(s3Client S3APIClient, cfg aws.Config, optFns ...func(*Options)) *Client {
return New(s3Client, Options{}, optFns...)
}
Loading

0 comments on commit 734b574

Please sign in to comment.